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
212,300
moodle/moodle
mod/lti/service/gradebookservices/backup/moodle2/restore_ltiservice_gradebookservices_subplugin.class.php
restore_ltiservice_gradebookservices_subplugin.define_lti_subplugin_structure
protected function define_lti_subplugin_structure() { $paths = array(); $elename = $this->get_namefor('lineitem'); $elepath = $this->get_pathfor('/lineitems/lineitem'); $paths[] = new restore_path_element($elename, $elepath); return $paths; }
php
protected function define_lti_subplugin_structure() { $paths = array(); $elename = $this->get_namefor('lineitem'); $elepath = $this->get_pathfor('/lineitems/lineitem'); $paths[] = new restore_path_element($elename, $elepath); return $paths; }
[ "protected", "function", "define_lti_subplugin_structure", "(", ")", "{", "$", "paths", "=", "array", "(", ")", ";", "$", "elename", "=", "$", "this", "->", "get_namefor", "(", "'lineitem'", ")", ";", "$", "elepath", "=", "$", "this", "->", "get_pathfor", "(", "'/lineitems/lineitem'", ")", ";", "$", "paths", "[", "]", "=", "new", "restore_path_element", "(", "$", "elename", ",", "$", "elepath", ")", ";", "return", "$", "paths", ";", "}" ]
Returns the subplugin structure to attach to the XML element. @return restore_path_element[] array of elements to be processed on restore.
[ "Returns", "the", "subplugin", "structure", "to", "attach", "to", "the", "XML", "element", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/lti/service/gradebookservices/backup/moodle2/restore_ltiservice_gradebookservices_subplugin.class.php#L50-L57
212,301
moodle/moodle
mod/lti/service/gradebookservices/backup/moodle2/restore_ltiservice_gradebookservices_subplugin.class.php
restore_ltiservice_gradebookservices_subplugin.process_ltiservice_gradebookservices_lineitem
public function process_ltiservice_gradebookservices_lineitem($data) { global $DB; $data = (object)$data; // The coupled lineitems are restored as any other grade item // so we will only create the entry in the ltiservice_gradebookservices table. // We will try to find a valid toolproxy in the system. // If it has been found before... we use it. /* cache parent property to account for missing PHPDoc type specification */ /** @var backup_activity_task $activitytask */ $activitytask = $this->task; $courseid = $activitytask->get_courseid(); if ($data->typeid != null) { if ($ltitypeid = $this->get_mappingid('ltitype', $data->typeid)) { $newtypeid = $ltitypeid; } else { // If not, then we will call our own function to find it. $newtypeid = $this->find_typeid($data, $courseid); } } else { $newtypeid = null; } if ($data->toolproxyid != null) { $ltitoolproxy = $this->get_mappingid('ltitoolproxy', $data->toolproxyid); if ($ltitoolproxy && $ltitoolproxy != 0) { $newtoolproxyid = $ltitoolproxy; } else { // If not, then we will call our own function to find it. $newtoolproxyid = $this->find_proxy_id($data); } } else { $newtoolproxyid = null; } if ($data->ltilinkid != null) { $ltilinkid = $this->get_new_parentid('lti'); } else { $ltilinkid = null; } // If this has not been restored before. if ($this->get_mappingid('gbsgradeitemrestored', $data->id, 0) == 0) { $newgbsid = $DB->insert_record('ltiservice_gradebookservices', (object) array( 'gradeitemid' => 0, 'courseid' => $courseid, 'toolproxyid' => $newtoolproxyid, 'ltilinkid' => $ltilinkid, 'typeid' => $newtypeid, 'baseurl' => $data->baseurl, 'tag' => $data->tag )); $this->set_mapping('gbsgradeitemoldid', $newgbsid, $data->gradeitemid); $this->set_mapping('gbsgradeitemrestored', $data->id, $data->id); } }
php
public function process_ltiservice_gradebookservices_lineitem($data) { global $DB; $data = (object)$data; // The coupled lineitems are restored as any other grade item // so we will only create the entry in the ltiservice_gradebookservices table. // We will try to find a valid toolproxy in the system. // If it has been found before... we use it. /* cache parent property to account for missing PHPDoc type specification */ /** @var backup_activity_task $activitytask */ $activitytask = $this->task; $courseid = $activitytask->get_courseid(); if ($data->typeid != null) { if ($ltitypeid = $this->get_mappingid('ltitype', $data->typeid)) { $newtypeid = $ltitypeid; } else { // If not, then we will call our own function to find it. $newtypeid = $this->find_typeid($data, $courseid); } } else { $newtypeid = null; } if ($data->toolproxyid != null) { $ltitoolproxy = $this->get_mappingid('ltitoolproxy', $data->toolproxyid); if ($ltitoolproxy && $ltitoolproxy != 0) { $newtoolproxyid = $ltitoolproxy; } else { // If not, then we will call our own function to find it. $newtoolproxyid = $this->find_proxy_id($data); } } else { $newtoolproxyid = null; } if ($data->ltilinkid != null) { $ltilinkid = $this->get_new_parentid('lti'); } else { $ltilinkid = null; } // If this has not been restored before. if ($this->get_mappingid('gbsgradeitemrestored', $data->id, 0) == 0) { $newgbsid = $DB->insert_record('ltiservice_gradebookservices', (object) array( 'gradeitemid' => 0, 'courseid' => $courseid, 'toolproxyid' => $newtoolproxyid, 'ltilinkid' => $ltilinkid, 'typeid' => $newtypeid, 'baseurl' => $data->baseurl, 'tag' => $data->tag )); $this->set_mapping('gbsgradeitemoldid', $newgbsid, $data->gradeitemid); $this->set_mapping('gbsgradeitemrestored', $data->id, $data->id); } }
[ "public", "function", "process_ltiservice_gradebookservices_lineitem", "(", "$", "data", ")", "{", "global", "$", "DB", ";", "$", "data", "=", "(", "object", ")", "$", "data", ";", "// The coupled lineitems are restored as any other grade item", "// so we will only create the entry in the ltiservice_gradebookservices table.", "// We will try to find a valid toolproxy in the system.", "// If it has been found before... we use it.", "/* cache parent property to account for missing PHPDoc type specification */", "/** @var backup_activity_task $activitytask */", "$", "activitytask", "=", "$", "this", "->", "task", ";", "$", "courseid", "=", "$", "activitytask", "->", "get_courseid", "(", ")", ";", "if", "(", "$", "data", "->", "typeid", "!=", "null", ")", "{", "if", "(", "$", "ltitypeid", "=", "$", "this", "->", "get_mappingid", "(", "'ltitype'", ",", "$", "data", "->", "typeid", ")", ")", "{", "$", "newtypeid", "=", "$", "ltitypeid", ";", "}", "else", "{", "// If not, then we will call our own function to find it.", "$", "newtypeid", "=", "$", "this", "->", "find_typeid", "(", "$", "data", ",", "$", "courseid", ")", ";", "}", "}", "else", "{", "$", "newtypeid", "=", "null", ";", "}", "if", "(", "$", "data", "->", "toolproxyid", "!=", "null", ")", "{", "$", "ltitoolproxy", "=", "$", "this", "->", "get_mappingid", "(", "'ltitoolproxy'", ",", "$", "data", "->", "toolproxyid", ")", ";", "if", "(", "$", "ltitoolproxy", "&&", "$", "ltitoolproxy", "!=", "0", ")", "{", "$", "newtoolproxyid", "=", "$", "ltitoolproxy", ";", "}", "else", "{", "// If not, then we will call our own function to find it.", "$", "newtoolproxyid", "=", "$", "this", "->", "find_proxy_id", "(", "$", "data", ")", ";", "}", "}", "else", "{", "$", "newtoolproxyid", "=", "null", ";", "}", "if", "(", "$", "data", "->", "ltilinkid", "!=", "null", ")", "{", "$", "ltilinkid", "=", "$", "this", "->", "get_new_parentid", "(", "'lti'", ")", ";", "}", "else", "{", "$", "ltilinkid", "=", "null", ";", "}", "// If this has not been restored before.", "if", "(", "$", "this", "->", "get_mappingid", "(", "'gbsgradeitemrestored'", ",", "$", "data", "->", "id", ",", "0", ")", "==", "0", ")", "{", "$", "newgbsid", "=", "$", "DB", "->", "insert_record", "(", "'ltiservice_gradebookservices'", ",", "(", "object", ")", "array", "(", "'gradeitemid'", "=>", "0", ",", "'courseid'", "=>", "$", "courseid", ",", "'toolproxyid'", "=>", "$", "newtoolproxyid", ",", "'ltilinkid'", "=>", "$", "ltilinkid", ",", "'typeid'", "=>", "$", "newtypeid", ",", "'baseurl'", "=>", "$", "data", "->", "baseurl", ",", "'tag'", "=>", "$", "data", "->", "tag", ")", ")", ";", "$", "this", "->", "set_mapping", "(", "'gbsgradeitemoldid'", ",", "$", "newgbsid", ",", "$", "data", "->", "gradeitemid", ")", ";", "$", "this", "->", "set_mapping", "(", "'gbsgradeitemrestored'", ",", "$", "data", "->", "id", ",", "$", "data", "->", "id", ")", ";", "}", "}" ]
Processes one lineitem @param mixed $data @return void
[ "Processes", "one", "lineitem" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/lti/service/gradebookservices/backup/moodle2/restore_ltiservice_gradebookservices_subplugin.class.php#L65-L114
212,302
moodle/moodle
mod/lti/service/gradebookservices/backup/moodle2/restore_ltiservice_gradebookservices_subplugin.class.php
restore_ltiservice_gradebookservices_subplugin.after_restore_lti
protected function after_restore_lti() { global $DB; $activitytask = $this->task; $courseid = $activitytask->get_courseid(); $gbstoupdate = $DB->get_records('ltiservice_gradebookservices', array('gradeitemid' => 0, 'courseid' => $courseid)); foreach ($gbstoupdate as $gbs) { $oldgradeitemid = $this->get_mappingid('gbsgradeitemoldid', $gbs->id, 0); $newgradeitemid = $this->get_mappingid('grade_item', $oldgradeitemid, 0); if ($newgradeitemid > 0) { $gbs->gradeitemid = $newgradeitemid; $DB->update_record('ltiservice_gradebookservices', $gbs); } } }
php
protected function after_restore_lti() { global $DB; $activitytask = $this->task; $courseid = $activitytask->get_courseid(); $gbstoupdate = $DB->get_records('ltiservice_gradebookservices', array('gradeitemid' => 0, 'courseid' => $courseid)); foreach ($gbstoupdate as $gbs) { $oldgradeitemid = $this->get_mappingid('gbsgradeitemoldid', $gbs->id, 0); $newgradeitemid = $this->get_mappingid('grade_item', $oldgradeitemid, 0); if ($newgradeitemid > 0) { $gbs->gradeitemid = $newgradeitemid; $DB->update_record('ltiservice_gradebookservices', $gbs); } } }
[ "protected", "function", "after_restore_lti", "(", ")", "{", "global", "$", "DB", ";", "$", "activitytask", "=", "$", "this", "->", "task", ";", "$", "courseid", "=", "$", "activitytask", "->", "get_courseid", "(", ")", ";", "$", "gbstoupdate", "=", "$", "DB", "->", "get_records", "(", "'ltiservice_gradebookservices'", ",", "array", "(", "'gradeitemid'", "=>", "0", ",", "'courseid'", "=>", "$", "courseid", ")", ")", ";", "foreach", "(", "$", "gbstoupdate", "as", "$", "gbs", ")", "{", "$", "oldgradeitemid", "=", "$", "this", "->", "get_mappingid", "(", "'gbsgradeitemoldid'", ",", "$", "gbs", "->", "id", ",", "0", ")", ";", "$", "newgradeitemid", "=", "$", "this", "->", "get_mappingid", "(", "'grade_item'", ",", "$", "oldgradeitemid", ",", "0", ")", ";", "if", "(", "$", "newgradeitemid", ">", "0", ")", "{", "$", "gbs", "->", "gradeitemid", "=", "$", "newgradeitemid", ";", "$", "DB", "->", "update_record", "(", "'ltiservice_gradebookservices'", ",", "$", "gbs", ")", ";", "}", "}", "}" ]
We call the after_restore_lti to update the grade_items id's that we didn't know in the moment of creating the gradebookservices rows.
[ "We", "call", "the", "after_restore_lti", "to", "update", "the", "grade_items", "id", "s", "that", "we", "didn", "t", "know", "in", "the", "moment", "of", "creating", "the", "gradebookservices", "rows", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/lti/service/gradebookservices/backup/moodle2/restore_ltiservice_gradebookservices_subplugin.class.php#L194-L207
212,303
moodle/moodle
privacy/classes/local/request/writer.php
writer.get_writer_instance
protected function get_writer_instance() : content_writer { if (null === $this->realwriter) { if (PHPUNIT_TEST) { $this->realwriter = new \core_privacy\tests\request\content_writer(static::instance()); } else { $this->realwriter = new moodle_content_writer(static::instance()); } } return $this->realwriter; }
php
protected function get_writer_instance() : content_writer { if (null === $this->realwriter) { if (PHPUNIT_TEST) { $this->realwriter = new \core_privacy\tests\request\content_writer(static::instance()); } else { $this->realwriter = new moodle_content_writer(static::instance()); } } return $this->realwriter; }
[ "protected", "function", "get_writer_instance", "(", ")", ":", "content_writer", "{", "if", "(", "null", "===", "$", "this", "->", "realwriter", ")", "{", "if", "(", "PHPUNIT_TEST", ")", "{", "$", "this", "->", "realwriter", "=", "new", "\\", "core_privacy", "\\", "tests", "\\", "request", "\\", "content_writer", "(", "static", "::", "instance", "(", ")", ")", ";", "}", "else", "{", "$", "this", "->", "realwriter", "=", "new", "moodle_content_writer", "(", "static", "::", "instance", "(", ")", ")", ";", "}", "}", "return", "$", "this", "->", "realwriter", ";", "}" ]
Singleton to return or create and return a copy of a content_writer. @return content_writer
[ "Singleton", "to", "return", "or", "create", "and", "return", "a", "copy", "of", "a", "content_writer", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/privacy/classes/local/request/writer.php#L58-L68
212,304
moodle/moodle
privacy/classes/local/request/writer.php
writer.setup_real_writer_instance
public static function setup_real_writer_instance() { if (!PHPUNIT_TEST) { throw new coding_exception('setup_real_writer_instance() is only for use with PHPUnit tests.'); } $instance = static::instance(); if (null === $instance->realwriter) { $instance->realwriter = new moodle_content_writer(static::instance()); } }
php
public static function setup_real_writer_instance() { if (!PHPUNIT_TEST) { throw new coding_exception('setup_real_writer_instance() is only for use with PHPUnit tests.'); } $instance = static::instance(); if (null === $instance->realwriter) { $instance->realwriter = new moodle_content_writer(static::instance()); } }
[ "public", "static", "function", "setup_real_writer_instance", "(", ")", "{", "if", "(", "!", "PHPUNIT_TEST", ")", "{", "throw", "new", "coding_exception", "(", "'setup_real_writer_instance() is only for use with PHPUnit tests.'", ")", ";", "}", "$", "instance", "=", "static", "::", "instance", "(", ")", ";", "if", "(", "null", "===", "$", "instance", "->", "realwriter", ")", "{", "$", "instance", "->", "realwriter", "=", "new", "moodle_content_writer", "(", "static", "::", "instance", "(", ")", ")", ";", "}", "}" ]
Create a real content_writer for use by PHPUnit tests, where a mock writer will not suffice. @return content_writer
[ "Create", "a", "real", "content_writer", "for", "use", "by", "PHPUnit", "tests", "where", "a", "mock", "writer", "will", "not", "suffice", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/privacy/classes/local/request/writer.php#L76-L86
212,305
moodle/moodle
question/classes/statistics/questions/calculated.php
calculated.random_selector_string
public function random_selector_string() { if ($this->question->qtype == 'random') { return $this->question->category .'/'. $this->question->questiontext; } else { return null; } }
php
public function random_selector_string() { if ($this->question->qtype == 'random') { return $this->question->category .'/'. $this->question->questiontext; } else { return null; } }
[ "public", "function", "random_selector_string", "(", ")", "{", "if", "(", "$", "this", "->", "question", "->", "qtype", "==", "'random'", ")", "{", "return", "$", "this", "->", "question", "->", "category", ".", "'/'", ".", "$", "this", "->", "question", "->", "questiontext", ";", "}", "else", "{", "return", "null", ";", "}", "}" ]
Used to determine which random questions pull sub questions from the same pools. Where pool means category and possibly all the sub categories of that category. @return null|string represents the pool of questions from which this question draws if it is random, or null if not.
[ "Used", "to", "determine", "which", "random", "questions", "pull", "sub", "questions", "from", "the", "same", "pools", ".", "Where", "pool", "means", "category", "and", "possibly", "all", "the", "sub", "categories", "of", "that", "category", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/classes/statistics/questions/calculated.php#L210-L216
212,306
moodle/moodle
question/classes/statistics/questions/calculated.php
calculated.cache
public function cache($qubaids) { global $DB; $toinsert = new \stdClass(); $toinsert->hashcode = $qubaids->get_hash_code(); $toinsert->timemodified = time(); foreach ($this->fieldsindb as $field) { $toinsert->{$field} = $this->{$field}; } $DB->insert_record('question_statistics', $toinsert, false); if ($this->get_variants()) { foreach ($this->variantstats as $variantstat) { $variantstat->cache($qubaids); } } }
php
public function cache($qubaids) { global $DB; $toinsert = new \stdClass(); $toinsert->hashcode = $qubaids->get_hash_code(); $toinsert->timemodified = time(); foreach ($this->fieldsindb as $field) { $toinsert->{$field} = $this->{$field}; } $DB->insert_record('question_statistics', $toinsert, false); if ($this->get_variants()) { foreach ($this->variantstats as $variantstat) { $variantstat->cache($qubaids); } } }
[ "public", "function", "cache", "(", "$", "qubaids", ")", "{", "global", "$", "DB", ";", "$", "toinsert", "=", "new", "\\", "stdClass", "(", ")", ";", "$", "toinsert", "->", "hashcode", "=", "$", "qubaids", "->", "get_hash_code", "(", ")", ";", "$", "toinsert", "->", "timemodified", "=", "time", "(", ")", ";", "foreach", "(", "$", "this", "->", "fieldsindb", "as", "$", "field", ")", "{", "$", "toinsert", "->", "{", "$", "field", "}", "=", "$", "this", "->", "{", "$", "field", "}", ";", "}", "$", "DB", "->", "insert_record", "(", "'question_statistics'", ",", "$", "toinsert", ",", "false", ")", ";", "if", "(", "$", "this", "->", "get_variants", "(", ")", ")", "{", "foreach", "(", "$", "this", "->", "variantstats", "as", "$", "variantstat", ")", "{", "$", "variantstat", "->", "cache", "(", "$", "qubaids", ")", ";", "}", "}", "}" ]
Cache calculated stats stored in this object in 'question_statistics' table. @param \qubaid_condition $qubaids
[ "Cache", "calculated", "stats", "stored", "in", "this", "object", "in", "question_statistics", "table", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/classes/statistics/questions/calculated.php#L223-L238
212,307
moodle/moodle
question/classes/statistics/questions/calculated.php
calculated.populate_from_record
public function populate_from_record($record) { foreach ($this->fieldsindb as $field) { $this->$field = $record->$field; } $this->timemodified = $record->timemodified; }
php
public function populate_from_record($record) { foreach ($this->fieldsindb as $field) { $this->$field = $record->$field; } $this->timemodified = $record->timemodified; }
[ "public", "function", "populate_from_record", "(", "$", "record", ")", "{", "foreach", "(", "$", "this", "->", "fieldsindb", "as", "$", "field", ")", "{", "$", "this", "->", "$", "field", "=", "$", "record", "->", "$", "field", ";", "}", "$", "this", "->", "timemodified", "=", "$", "record", "->", "timemodified", ";", "}" ]
Load properties of this class from db record. @param object $record Given a record from 'question_statistics' copy stats from record to properties.
[ "Load", "properties", "of", "this", "class", "from", "db", "record", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/classes/statistics/questions/calculated.php#L245-L250
212,308
moodle/moodle
question/classes/statistics/questions/calculated.php
calculated.get_variants
public function get_variants() { $variants = array_keys($this->variantstats); if (count($variants) > 1 || reset($variants) != 1) { return $variants; } else { return array(); } }
php
public function get_variants() { $variants = array_keys($this->variantstats); if (count($variants) > 1 || reset($variants) != 1) { return $variants; } else { return array(); } }
[ "public", "function", "get_variants", "(", ")", "{", "$", "variants", "=", "array_keys", "(", "$", "this", "->", "variantstats", ")", ";", "if", "(", "count", "(", "$", "variants", ")", ">", "1", "||", "reset", "(", "$", "variants", ")", "!=", "1", ")", "{", "return", "$", "variants", ";", "}", "else", "{", "return", "array", "(", ")", ";", "}", "}" ]
Array of variants that have appeared in the attempt data for this question. Or an empty array if there is only one variant. @return int[] the variant nos.
[ "Array", "of", "variants", "that", "have", "appeared", "in", "the", "attempt", "data", "for", "this", "question", ".", "Or", "an", "empty", "array", "if", "there", "is", "only", "one", "variant", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/classes/statistics/questions/calculated.php#L277-L284
212,309
moodle/moodle
question/classes/statistics/questions/calculated.php
calculated.break_down_by_variant
public function break_down_by_variant() { $qtype = \question_bank::get_qtype($this->question->qtype); return $qtype->break_down_stats_and_response_analysis_by_variant($this->question); }
php
public function break_down_by_variant() { $qtype = \question_bank::get_qtype($this->question->qtype); return $qtype->break_down_stats_and_response_analysis_by_variant($this->question); }
[ "public", "function", "break_down_by_variant", "(", ")", "{", "$", "qtype", "=", "\\", "question_bank", "::", "get_qtype", "(", "$", "this", "->", "question", "->", "qtype", ")", ";", "return", "$", "qtype", "->", "break_down_stats_and_response_analysis_by_variant", "(", "$", "this", "->", "question", ")", ";", "}" ]
Do we break down the stats for this question by variant or not? @return bool Do we?
[ "Do", "we", "break", "down", "the", "stats", "for", "this", "question", "by", "variant", "or", "not?" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/classes/statistics/questions/calculated.php#L291-L294
212,310
moodle/moodle
lib/behat/classes/behat_context_helper.php
behat_context_helper.get
public static function get($classname) { $contexts = self::$environment->getContexts(); foreach ($contexts as $context) { if (is_a($context, $classname)) { return $context; } } $suitename = self::$environment->getSuite()->getName(); // If default suite, then get the default theme name. if ($suitename == 'default') { $suitename = theme_config::DEFAULT_THEME; } $overridencontextname = 'behat_theme_'.$suitename.'_'.$classname; // If contexts has not been checked before and doesn't exist then just use core one. if (!isset(self::$nonexistingcontexts[$overridencontextname])) { try { $subcontext = self::$environment->getContext($overridencontextname); return $subcontext; } catch (Behat\Behat\Context\Exception\ContextNotFoundException $e) { // If context not found then it's not overridden. self::$nonexistingcontexts[$overridencontextname] = 1; } } // Get the actual context. return self::$environment->getContext($classname); }
php
public static function get($classname) { $contexts = self::$environment->getContexts(); foreach ($contexts as $context) { if (is_a($context, $classname)) { return $context; } } $suitename = self::$environment->getSuite()->getName(); // If default suite, then get the default theme name. if ($suitename == 'default') { $suitename = theme_config::DEFAULT_THEME; } $overridencontextname = 'behat_theme_'.$suitename.'_'.$classname; // If contexts has not been checked before and doesn't exist then just use core one. if (!isset(self::$nonexistingcontexts[$overridencontextname])) { try { $subcontext = self::$environment->getContext($overridencontextname); return $subcontext; } catch (Behat\Behat\Context\Exception\ContextNotFoundException $e) { // If context not found then it's not overridden. self::$nonexistingcontexts[$overridencontextname] = 1; } } // Get the actual context. return self::$environment->getContext($classname); }
[ "public", "static", "function", "get", "(", "$", "classname", ")", "{", "$", "contexts", "=", "self", "::", "$", "environment", "->", "getContexts", "(", ")", ";", "foreach", "(", "$", "contexts", "as", "$", "context", ")", "{", "if", "(", "is_a", "(", "$", "context", ",", "$", "classname", ")", ")", "{", "return", "$", "context", ";", "}", "}", "$", "suitename", "=", "self", "::", "$", "environment", "->", "getSuite", "(", ")", "->", "getName", "(", ")", ";", "// If default suite, then get the default theme name.", "if", "(", "$", "suitename", "==", "'default'", ")", "{", "$", "suitename", "=", "theme_config", "::", "DEFAULT_THEME", ";", "}", "$", "overridencontextname", "=", "'behat_theme_'", ".", "$", "suitename", ".", "'_'", ".", "$", "classname", ";", "// If contexts has not been checked before and doesn't exist then just use core one.", "if", "(", "!", "isset", "(", "self", "::", "$", "nonexistingcontexts", "[", "$", "overridencontextname", "]", ")", ")", "{", "try", "{", "$", "subcontext", "=", "self", "::", "$", "environment", "->", "getContext", "(", "$", "overridencontextname", ")", ";", "return", "$", "subcontext", ";", "}", "catch", "(", "Behat", "\\", "Behat", "\\", "Context", "\\", "Exception", "\\", "ContextNotFoundException", "$", "e", ")", "{", "// If context not found then it's not overridden.", "self", "::", "$", "nonexistingcontexts", "[", "$", "overridencontextname", "]", "=", "1", ";", "}", "}", "// Get the actual context.", "return", "self", "::", "$", "environment", "->", "getContext", "(", "$", "classname", ")", ";", "}" ]
Gets the required context. Getting a context you get access to all the steps that uses direct API calls; steps returning step chains can not be executed like this. @throws Behat\Behat\Context\Exception\ContextNotFoundException @param string $classname Context identifier (the class name). @return behat_base
[ "Gets", "the", "required", "context", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/behat/classes/behat_context_helper.php#L92-L122
212,311
moodle/moodle
lib/behat/classes/behat_context_helper.php
behat_context_helper.escape
public static function escape($label) { if (empty(self::$escaper)) { self::$escaper = new \Behat\Mink\Selector\Xpath\Escaper(); } return self::$escaper->escapeLiteral($label); }
php
public static function escape($label) { if (empty(self::$escaper)) { self::$escaper = new \Behat\Mink\Selector\Xpath\Escaper(); } return self::$escaper->escapeLiteral($label); }
[ "public", "static", "function", "escape", "(", "$", "label", ")", "{", "if", "(", "empty", "(", "self", "::", "$", "escaper", ")", ")", "{", "self", "::", "$", "escaper", "=", "new", "\\", "Behat", "\\", "Mink", "\\", "Selector", "\\", "Xpath", "\\", "Escaper", "(", ")", ";", "}", "return", "self", "::", "$", "escaper", "->", "escapeLiteral", "(", "$", "label", ")", ";", "}" ]
Translates string to XPath literal. @param string $label label to escape @return string escaped string.
[ "Translates", "string", "to", "XPath", "literal", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/behat/classes/behat_context_helper.php#L130-L135
212,312
moodle/moodle
lib/horde/framework/Horde/Imap/Client/Data/Namespace.php
Horde_Imap_Client_Data_Namespace.stripNamespace
public function stripNamespace($mbox) { $mbox = strval($mbox); $name = $this->name; return (strlen($name) && (strpos($mbox, $name) === 0)) ? substr($mbox, strlen($name)) : $mbox; }
php
public function stripNamespace($mbox) { $mbox = strval($mbox); $name = $this->name; return (strlen($name) && (strpos($mbox, $name) === 0)) ? substr($mbox, strlen($name)) : $mbox; }
[ "public", "function", "stripNamespace", "(", "$", "mbox", ")", "{", "$", "mbox", "=", "strval", "(", "$", "mbox", ")", ";", "$", "name", "=", "$", "this", "->", "name", ";", "return", "(", "strlen", "(", "$", "name", ")", "&&", "(", "strpos", "(", "$", "mbox", ",", "$", "name", ")", "===", "0", ")", ")", "?", "substr", "(", "$", "mbox", ",", "strlen", "(", "$", "name", ")", ")", ":", "$", "mbox", ";", "}" ]
Strips namespace information from the given mailbox name. @param string $mbox Mailbox name. @return string Mailbox name with namespace prefix stripped.
[ "Strips", "namespace", "information", "from", "the", "given", "mailbox", "name", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/horde/framework/Horde/Imap/Client/Data/Namespace.php#L55-L63
212,313
moodle/moodle
mod/feedback/classes/complete_form.php
mod_feedback_complete_form.remove_button
private function remove_button($buttonname) { $el = $this->_form->getElement('buttonar'); foreach ($el->_elements as $idx => $button) { if ($button instanceof MoodleQuickForm_submit && $button->getName() === $buttonname) { unset($el->_elements[$idx]); return; } } }
php
private function remove_button($buttonname) { $el = $this->_form->getElement('buttonar'); foreach ($el->_elements as $idx => $button) { if ($button instanceof MoodleQuickForm_submit && $button->getName() === $buttonname) { unset($el->_elements[$idx]); return; } } }
[ "private", "function", "remove_button", "(", "$", "buttonname", ")", "{", "$", "el", "=", "$", "this", "->", "_form", "->", "getElement", "(", "'buttonar'", ")", ";", "foreach", "(", "$", "el", "->", "_elements", "as", "$", "idx", "=>", "$", "button", ")", "{", "if", "(", "$", "button", "instanceof", "MoodleQuickForm_submit", "&&", "$", "button", "->", "getName", "(", ")", "===", "$", "buttonname", ")", "{", "unset", "(", "$", "el", "->", "_elements", "[", "$", "idx", "]", ")", ";", "return", ";", "}", "}", "}" ]
Removes the button that is not applicable for the current page @param string $buttonname
[ "Removes", "the", "button", "that", "is", "not", "applicable", "for", "the", "current", "page" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/feedback/classes/complete_form.php#L181-L189
212,314
moodle/moodle
mod/feedback/classes/complete_form.php
mod_feedback_complete_form.get_item_value
public function get_item_value($item) { if ($this->structure instanceof mod_feedback_completion) { return $this->structure->get_item_value($item); } return null; }
php
public function get_item_value($item) { if ($this->structure instanceof mod_feedback_completion) { return $this->structure->get_item_value($item); } return null; }
[ "public", "function", "get_item_value", "(", "$", "item", ")", "{", "if", "(", "$", "this", "->", "structure", "instanceof", "mod_feedback_completion", ")", "{", "return", "$", "this", "->", "structure", "->", "get_item_value", "(", "$", "item", ")", ";", "}", "return", "null", ";", "}" ]
Returns value for this element that is already stored in temporary or permanent table, usually only available when user clicked "Previous page". Null means no value is stored. @param stdClass $item @return string
[ "Returns", "value", "for", "this", "element", "that", "is", "already", "stored", "in", "temporary", "or", "permanent", "table", "usually", "only", "available", "when", "user", "clicked", "Previous", "page", ".", "Null", "means", "no", "value", "is", "stored", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/feedback/classes/complete_form.php#L198-L203
212,315
moodle/moodle
mod/feedback/classes/complete_form.php
mod_feedback_complete_form.get_suggested_class
protected function get_suggested_class($item) { $class = "feedback_itemlist feedback-item-{$item->typ}"; if ($item->dependitem) { $class .= " feedback_is_dependent"; } if ($item->typ !== 'pagebreak') { $itemobj = feedback_get_item_class($item->typ); if ($itemobj->get_hasvalue()) { $class .= " feedback_hasvalue"; } } return $class; }
php
protected function get_suggested_class($item) { $class = "feedback_itemlist feedback-item-{$item->typ}"; if ($item->dependitem) { $class .= " feedback_is_dependent"; } if ($item->typ !== 'pagebreak') { $itemobj = feedback_get_item_class($item->typ); if ($itemobj->get_hasvalue()) { $class .= " feedback_hasvalue"; } } return $class; }
[ "protected", "function", "get_suggested_class", "(", "$", "item", ")", "{", "$", "class", "=", "\"feedback_itemlist feedback-item-{$item->typ}\"", ";", "if", "(", "$", "item", "->", "dependitem", ")", "{", "$", "class", ".=", "\" feedback_is_dependent\"", ";", "}", "if", "(", "$", "item", "->", "typ", "!==", "'pagebreak'", ")", "{", "$", "itemobj", "=", "feedback_get_item_class", "(", "$", "item", "->", "typ", ")", ";", "if", "(", "$", "itemobj", "->", "get_hasvalue", "(", ")", ")", "{", "$", "class", ".=", "\" feedback_hasvalue\"", ";", "}", "}", "return", "$", "class", ";", "}" ]
CSS class for the item @param stdClass $item @return string
[ "CSS", "class", "for", "the", "item" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/feedback/classes/complete_form.php#L270-L282
212,316
moodle/moodle
mod/feedback/classes/complete_form.php
mod_feedback_complete_form.add_item_label
protected function add_item_label($item, $element) { if (strlen($item->label) && ($this->mode == self::MODE_EDIT || $this->mode == self::MODE_VIEW_TEMPLATE)) { $name = $element->getLabel(); $name = '('.format_string($item->label).') '.$name; $element->setLabel($name); } }
php
protected function add_item_label($item, $element) { if (strlen($item->label) && ($this->mode == self::MODE_EDIT || $this->mode == self::MODE_VIEW_TEMPLATE)) { $name = $element->getLabel(); $name = '('.format_string($item->label).') '.$name; $element->setLabel($name); } }
[ "protected", "function", "add_item_label", "(", "$", "item", ",", "$", "element", ")", "{", "if", "(", "strlen", "(", "$", "item", "->", "label", ")", "&&", "(", "$", "this", "->", "mode", "==", "self", "::", "MODE_EDIT", "||", "$", "this", "->", "mode", "==", "self", "::", "MODE_VIEW_TEMPLATE", ")", ")", "{", "$", "name", "=", "$", "element", "->", "getLabel", "(", ")", ";", "$", "name", "=", "'('", ".", "format_string", "(", "$", "item", "->", "label", ")", ".", "') '", ".", "$", "name", ";", "$", "element", "->", "setLabel", "(", "$", "name", ")", ";", "}", "}" ]
Adds an item label to the question name @param stdClass $item @param HTML_QuickForm_element $element
[ "Adds", "an", "item", "label", "to", "the", "question", "name" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/feedback/classes/complete_form.php#L400-L406
212,317
moodle/moodle
mod/feedback/classes/complete_form.php
mod_feedback_complete_form.add_item_dependencies
protected function add_item_dependencies($item, $element) { $allitems = $this->structure->get_items(); if ($item->dependitem && ($this->mode == self::MODE_EDIT || $this->mode == self::MODE_VIEW_TEMPLATE)) { if (isset($allitems[$item->dependitem])) { $dependitem = $allitems[$item->dependitem]; $name = $element->getLabel(); $name .= html_writer::span(' ('.format_string($dependitem->label).'->'.$item->dependvalue.')', 'feedback_depend'); $element->setLabel($name); } } }
php
protected function add_item_dependencies($item, $element) { $allitems = $this->structure->get_items(); if ($item->dependitem && ($this->mode == self::MODE_EDIT || $this->mode == self::MODE_VIEW_TEMPLATE)) { if (isset($allitems[$item->dependitem])) { $dependitem = $allitems[$item->dependitem]; $name = $element->getLabel(); $name .= html_writer::span(' ('.format_string($dependitem->label).'->'.$item->dependvalue.')', 'feedback_depend'); $element->setLabel($name); } } }
[ "protected", "function", "add_item_dependencies", "(", "$", "item", ",", "$", "element", ")", "{", "$", "allitems", "=", "$", "this", "->", "structure", "->", "get_items", "(", ")", ";", "if", "(", "$", "item", "->", "dependitem", "&&", "(", "$", "this", "->", "mode", "==", "self", "::", "MODE_EDIT", "||", "$", "this", "->", "mode", "==", "self", "::", "MODE_VIEW_TEMPLATE", ")", ")", "{", "if", "(", "isset", "(", "$", "allitems", "[", "$", "item", "->", "dependitem", "]", ")", ")", "{", "$", "dependitem", "=", "$", "allitems", "[", "$", "item", "->", "dependitem", "]", ";", "$", "name", "=", "$", "element", "->", "getLabel", "(", ")", ";", "$", "name", ".=", "html_writer", "::", "span", "(", "' ('", ".", "format_string", "(", "$", "dependitem", "->", "label", ")", ".", "'->'", ".", "$", "item", "->", "dependvalue", ".", "')'", ",", "'feedback_depend'", ")", ";", "$", "element", "->", "setLabel", "(", "$", "name", ")", ";", "}", "}", "}" ]
Adds a dependency description to the question name @param stdClass $item @param HTML_QuickForm_element $element
[ "Adds", "a", "dependency", "description", "to", "the", "question", "name" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/feedback/classes/complete_form.php#L413-L424
212,318
moodle/moodle
mod/feedback/classes/complete_form.php
mod_feedback_complete_form.guess_element_id
protected function guess_element_id($item, $element) { if (!$id = $element->getAttribute('id')) { $attributes = $element->getAttributes(); $id = $attributes['id'] = 'feedback_item_' . $item->id; $element->setAttributes($attributes); } if ($element->getType() === 'group') { return 'fgroup_' . $id; } return 'fitem_' . $id; }
php
protected function guess_element_id($item, $element) { if (!$id = $element->getAttribute('id')) { $attributes = $element->getAttributes(); $id = $attributes['id'] = 'feedback_item_' . $item->id; $element->setAttributes($attributes); } if ($element->getType() === 'group') { return 'fgroup_' . $id; } return 'fitem_' . $id; }
[ "protected", "function", "guess_element_id", "(", "$", "item", ",", "$", "element", ")", "{", "if", "(", "!", "$", "id", "=", "$", "element", "->", "getAttribute", "(", "'id'", ")", ")", "{", "$", "attributes", "=", "$", "element", "->", "getAttributes", "(", ")", ";", "$", "id", "=", "$", "attributes", "[", "'id'", "]", "=", "'feedback_item_'", ".", "$", "item", "->", "id", ";", "$", "element", "->", "setAttributes", "(", "$", "attributes", ")", ";", "}", "if", "(", "$", "element", "->", "getType", "(", ")", "===", "'group'", ")", "{", "return", "'fgroup_'", ".", "$", "id", ";", "}", "return", "'fitem_'", ".", "$", "id", ";", "}" ]
Returns the CSS id attribute that will be assigned by moodleform later to this element @param stdClass $item @param HTML_QuickForm_element $element
[ "Returns", "the", "CSS", "id", "attribute", "that", "will", "be", "assigned", "by", "moodleform", "later", "to", "this", "element" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/feedback/classes/complete_form.php#L431-L441
212,319
moodle/moodle
mod/feedback/classes/complete_form.php
mod_feedback_complete_form.enhance_name_for_edit
protected function enhance_name_for_edit($item, $element) { global $OUTPUT; $menu = new action_menu(); $menu->set_owner_selector('#' . $this->guess_element_id($item, $element)); $menu->set_constraint('.feedback_form'); $menu->set_alignment(action_menu::TR, action_menu::BR); $menu->set_menu_trigger(get_string('edit')); $menu->prioritise = true; $itemobj = feedback_get_item_class($item->typ); $actions = $itemobj->edit_actions($item, $this->get_feedback(), $this->get_cm()); foreach ($actions as $action) { $menu->add($action); } $editmenu = $OUTPUT->render($menu); $name = $element->getLabel(); $name = html_writer::span('', 'itemdd', array('id' => 'feedback_item_box_' . $item->id)) . html_writer::span($name, 'itemname') . html_writer::span($editmenu, 'itemactions'); $element->setLabel(html_writer::span($name, 'itemtitle')); }
php
protected function enhance_name_for_edit($item, $element) { global $OUTPUT; $menu = new action_menu(); $menu->set_owner_selector('#' . $this->guess_element_id($item, $element)); $menu->set_constraint('.feedback_form'); $menu->set_alignment(action_menu::TR, action_menu::BR); $menu->set_menu_trigger(get_string('edit')); $menu->prioritise = true; $itemobj = feedback_get_item_class($item->typ); $actions = $itemobj->edit_actions($item, $this->get_feedback(), $this->get_cm()); foreach ($actions as $action) { $menu->add($action); } $editmenu = $OUTPUT->render($menu); $name = $element->getLabel(); $name = html_writer::span('', 'itemdd', array('id' => 'feedback_item_box_' . $item->id)) . html_writer::span($name, 'itemname') . html_writer::span($editmenu, 'itemactions'); $element->setLabel(html_writer::span($name, 'itemtitle')); }
[ "protected", "function", "enhance_name_for_edit", "(", "$", "item", ",", "$", "element", ")", "{", "global", "$", "OUTPUT", ";", "$", "menu", "=", "new", "action_menu", "(", ")", ";", "$", "menu", "->", "set_owner_selector", "(", "'#'", ".", "$", "this", "->", "guess_element_id", "(", "$", "item", ",", "$", "element", ")", ")", ";", "$", "menu", "->", "set_constraint", "(", "'.feedback_form'", ")", ";", "$", "menu", "->", "set_alignment", "(", "action_menu", "::", "TR", ",", "action_menu", "::", "BR", ")", ";", "$", "menu", "->", "set_menu_trigger", "(", "get_string", "(", "'edit'", ")", ")", ";", "$", "menu", "->", "prioritise", "=", "true", ";", "$", "itemobj", "=", "feedback_get_item_class", "(", "$", "item", "->", "typ", ")", ";", "$", "actions", "=", "$", "itemobj", "->", "edit_actions", "(", "$", "item", ",", "$", "this", "->", "get_feedback", "(", ")", ",", "$", "this", "->", "get_cm", "(", ")", ")", ";", "foreach", "(", "$", "actions", "as", "$", "action", ")", "{", "$", "menu", "->", "add", "(", "$", "action", ")", ";", "}", "$", "editmenu", "=", "$", "OUTPUT", "->", "render", "(", "$", "menu", ")", ";", "$", "name", "=", "$", "element", "->", "getLabel", "(", ")", ";", "$", "name", "=", "html_writer", "::", "span", "(", "''", ",", "'itemdd'", ",", "array", "(", "'id'", "=>", "'feedback_item_box_'", ".", "$", "item", "->", "id", ")", ")", ".", "html_writer", "::", "span", "(", "$", "name", ",", "'itemname'", ")", ".", "html_writer", "::", "span", "(", "$", "editmenu", ",", "'itemactions'", ")", ";", "$", "element", "->", "setLabel", "(", "html_writer", "::", "span", "(", "$", "name", ",", "'itemtitle'", ")", ")", ";", "}" ]
Adds editing actions to the question name in the edit mode @param stdClass $item @param HTML_QuickForm_element $element
[ "Adds", "editing", "actions", "to", "the", "question", "name", "in", "the", "edit", "mode" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/feedback/classes/complete_form.php#L448-L470
212,320
moodle/moodle
mod/feedback/classes/complete_form.php
mod_feedback_complete_form.add_validation_rule
public function add_validation_rule(callable $callback) { if ($this->mode == self::MODE_COMPLETE) { $this->_form->addFormRule($callback); } }
php
public function add_validation_rule(callable $callback) { if ($this->mode == self::MODE_COMPLETE) { $this->_form->addFormRule($callback); } }
[ "public", "function", "add_validation_rule", "(", "callable", "$", "callback", ")", "{", "if", "(", "$", "this", "->", "mode", "==", "self", "::", "MODE_COMPLETE", ")", "{", "$", "this", "->", "_form", "->", "addFormRule", "(", "$", "callback", ")", ";", "}", "}" ]
Adds a validation rule to the form @param callable $callback with arguments ($values, $files)
[ "Adds", "a", "validation", "rule", "to", "the", "form" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/feedback/classes/complete_form.php#L525-L529
212,321
moodle/moodle
enrol/ldap/lib.php
enrol_ldap_plugin.ldap_find_user_groups_recursively
protected function ldap_find_user_groups_recursively($memberdn, &$membergroups) { $result = @ldap_read($this->ldapconnection, $memberdn, '(objectClass=*)', array($this->get_config('group_memberofattribute'))); if (!$result) { return; } if ($entry = ldap_first_entry($this->ldapconnection, $result)) { do { $attributes = ldap_get_attributes($this->ldapconnection, $entry); for ($j = 0; $j < $attributes['count']; $j++) { $groups = ldap_get_values_len($this->ldapconnection, $entry, $attributes[$j]); foreach ($groups as $key => $group) { if ($key === 'count') { // Skip the entries count continue; } if(!in_array($group, $membergroups)) { // Only push and recurse if we haven't 'seen' this group before // to prevent loops (MS Active Directory allows them!!). array_push($membergroups, $group); $this->ldap_find_user_groups_recursively($group, $membergroups); } } } } while ($entry = ldap_next_entry($this->ldapconnection, $entry)); } }
php
protected function ldap_find_user_groups_recursively($memberdn, &$membergroups) { $result = @ldap_read($this->ldapconnection, $memberdn, '(objectClass=*)', array($this->get_config('group_memberofattribute'))); if (!$result) { return; } if ($entry = ldap_first_entry($this->ldapconnection, $result)) { do { $attributes = ldap_get_attributes($this->ldapconnection, $entry); for ($j = 0; $j < $attributes['count']; $j++) { $groups = ldap_get_values_len($this->ldapconnection, $entry, $attributes[$j]); foreach ($groups as $key => $group) { if ($key === 'count') { // Skip the entries count continue; } if(!in_array($group, $membergroups)) { // Only push and recurse if we haven't 'seen' this group before // to prevent loops (MS Active Directory allows them!!). array_push($membergroups, $group); $this->ldap_find_user_groups_recursively($group, $membergroups); } } } } while ($entry = ldap_next_entry($this->ldapconnection, $entry)); } }
[ "protected", "function", "ldap_find_user_groups_recursively", "(", "$", "memberdn", ",", "&", "$", "membergroups", ")", "{", "$", "result", "=", "@", "ldap_read", "(", "$", "this", "->", "ldapconnection", ",", "$", "memberdn", ",", "'(objectClass=*)'", ",", "array", "(", "$", "this", "->", "get_config", "(", "'group_memberofattribute'", ")", ")", ")", ";", "if", "(", "!", "$", "result", ")", "{", "return", ";", "}", "if", "(", "$", "entry", "=", "ldap_first_entry", "(", "$", "this", "->", "ldapconnection", ",", "$", "result", ")", ")", "{", "do", "{", "$", "attributes", "=", "ldap_get_attributes", "(", "$", "this", "->", "ldapconnection", ",", "$", "entry", ")", ";", "for", "(", "$", "j", "=", "0", ";", "$", "j", "<", "$", "attributes", "[", "'count'", "]", ";", "$", "j", "++", ")", "{", "$", "groups", "=", "ldap_get_values_len", "(", "$", "this", "->", "ldapconnection", ",", "$", "entry", ",", "$", "attributes", "[", "$", "j", "]", ")", ";", "foreach", "(", "$", "groups", "as", "$", "key", "=>", "$", "group", ")", "{", "if", "(", "$", "key", "===", "'count'", ")", "{", "// Skip the entries count", "continue", ";", "}", "if", "(", "!", "in_array", "(", "$", "group", ",", "$", "membergroups", ")", ")", "{", "// Only push and recurse if we haven't 'seen' this group before", "// to prevent loops (MS Active Directory allows them!!).", "array_push", "(", "$", "membergroups", ",", "$", "group", ")", ";", "$", "this", "->", "ldap_find_user_groups_recursively", "(", "$", "group", ",", "$", "membergroups", ")", ";", "}", "}", "}", "}", "while", "(", "$", "entry", "=", "ldap_next_entry", "(", "$", "this", "->", "ldapconnection", ",", "$", "entry", ")", ")", ";", "}", "}" ]
Recursively process the groups the given member distinguished name belongs to, adding them to the already processed groups array. @param string $memberdn distinguished name to search @param array reference &$membergroups array with already found groups, where we'll put the newly found groups.
[ "Recursively", "process", "the", "groups", "the", "given", "member", "distinguished", "name", "belongs", "to", "adding", "them", "to", "the", "already", "processed", "groups", "array", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/enrol/ldap/lib.php#L870-L896
212,322
moodle/moodle
enrol/ldap/lib.php
enrol_ldap_plugin.update_course
protected function update_course($course, $externalcourse, progress_trace $trace) { global $CFG, $DB; $coursefields = array ('shortname', 'fullname', 'summary'); static $shouldupdate; // Initialize $shouldupdate variable. Set to true if one or more fields are marked for update. if (!isset($shouldupdate)) { $shouldupdate = false; foreach ($coursefields as $field) { $shouldupdate = $shouldupdate || $this->get_config('course_'.$field.'_updateonsync'); } } // If we should not update return immediately. if (!$shouldupdate) { return false; } require_once("$CFG->dirroot/course/lib.php"); $courseupdated = false; $updatedcourse = new stdClass(); $updatedcourse->id = $course->id; // Update course fields if necessary. foreach ($coursefields as $field) { // If field is marked to be updated on sync && field data was changed update it. if ($this->get_config('course_'.$field.'_updateonsync') && isset($externalcourse[$this->get_config('course_'.$field)][0]) && $course->{$field} != $externalcourse[$this->get_config('course_'.$field)][0]) { $updatedcourse->{$field} = $externalcourse[$this->get_config('course_'.$field)][0]; $courseupdated = true; } } if (!$courseupdated) { $trace->output(get_string('courseupdateskipped', 'enrol_ldap', $course)); return false; } // Do not allow empty fullname or shortname. if ((isset($updatedcourse->fullname) && empty($updatedcourse->fullname)) || (isset($updatedcourse->shortname) && empty($updatedcourse->shortname))) { // We are in trouble! $trace->output(get_string('cannotupdatecourse', 'enrol_ldap', $course)); return false; } // Check if the shortname already exists if it does - skip course updating. if (isset($updatedcourse->shortname) && $DB->record_exists('course', array('shortname' => $updatedcourse->shortname))) { $trace->output(get_string('cannotupdatecourse_duplicateshortname', 'enrol_ldap', $course)); return false; } // Finally - update course in DB. update_course($updatedcourse); $trace->output(get_string('courseupdated', 'enrol_ldap', $course)); return true; }
php
protected function update_course($course, $externalcourse, progress_trace $trace) { global $CFG, $DB; $coursefields = array ('shortname', 'fullname', 'summary'); static $shouldupdate; // Initialize $shouldupdate variable. Set to true if one or more fields are marked for update. if (!isset($shouldupdate)) { $shouldupdate = false; foreach ($coursefields as $field) { $shouldupdate = $shouldupdate || $this->get_config('course_'.$field.'_updateonsync'); } } // If we should not update return immediately. if (!$shouldupdate) { return false; } require_once("$CFG->dirroot/course/lib.php"); $courseupdated = false; $updatedcourse = new stdClass(); $updatedcourse->id = $course->id; // Update course fields if necessary. foreach ($coursefields as $field) { // If field is marked to be updated on sync && field data was changed update it. if ($this->get_config('course_'.$field.'_updateonsync') && isset($externalcourse[$this->get_config('course_'.$field)][0]) && $course->{$field} != $externalcourse[$this->get_config('course_'.$field)][0]) { $updatedcourse->{$field} = $externalcourse[$this->get_config('course_'.$field)][0]; $courseupdated = true; } } if (!$courseupdated) { $trace->output(get_string('courseupdateskipped', 'enrol_ldap', $course)); return false; } // Do not allow empty fullname or shortname. if ((isset($updatedcourse->fullname) && empty($updatedcourse->fullname)) || (isset($updatedcourse->shortname) && empty($updatedcourse->shortname))) { // We are in trouble! $trace->output(get_string('cannotupdatecourse', 'enrol_ldap', $course)); return false; } // Check if the shortname already exists if it does - skip course updating. if (isset($updatedcourse->shortname) && $DB->record_exists('course', array('shortname' => $updatedcourse->shortname))) { $trace->output(get_string('cannotupdatecourse_duplicateshortname', 'enrol_ldap', $course)); return false; } // Finally - update course in DB. update_course($updatedcourse); $trace->output(get_string('courseupdated', 'enrol_ldap', $course)); return true; }
[ "protected", "function", "update_course", "(", "$", "course", ",", "$", "externalcourse", ",", "progress_trace", "$", "trace", ")", "{", "global", "$", "CFG", ",", "$", "DB", ";", "$", "coursefields", "=", "array", "(", "'shortname'", ",", "'fullname'", ",", "'summary'", ")", ";", "static", "$", "shouldupdate", ";", "// Initialize $shouldupdate variable. Set to true if one or more fields are marked for update.", "if", "(", "!", "isset", "(", "$", "shouldupdate", ")", ")", "{", "$", "shouldupdate", "=", "false", ";", "foreach", "(", "$", "coursefields", "as", "$", "field", ")", "{", "$", "shouldupdate", "=", "$", "shouldupdate", "||", "$", "this", "->", "get_config", "(", "'course_'", ".", "$", "field", ".", "'_updateonsync'", ")", ";", "}", "}", "// If we should not update return immediately.", "if", "(", "!", "$", "shouldupdate", ")", "{", "return", "false", ";", "}", "require_once", "(", "\"$CFG->dirroot/course/lib.php\"", ")", ";", "$", "courseupdated", "=", "false", ";", "$", "updatedcourse", "=", "new", "stdClass", "(", ")", ";", "$", "updatedcourse", "->", "id", "=", "$", "course", "->", "id", ";", "// Update course fields if necessary.", "foreach", "(", "$", "coursefields", "as", "$", "field", ")", "{", "// If field is marked to be updated on sync && field data was changed update it.", "if", "(", "$", "this", "->", "get_config", "(", "'course_'", ".", "$", "field", ".", "'_updateonsync'", ")", "&&", "isset", "(", "$", "externalcourse", "[", "$", "this", "->", "get_config", "(", "'course_'", ".", "$", "field", ")", "]", "[", "0", "]", ")", "&&", "$", "course", "->", "{", "$", "field", "}", "!=", "$", "externalcourse", "[", "$", "this", "->", "get_config", "(", "'course_'", ".", "$", "field", ")", "]", "[", "0", "]", ")", "{", "$", "updatedcourse", "->", "{", "$", "field", "}", "=", "$", "externalcourse", "[", "$", "this", "->", "get_config", "(", "'course_'", ".", "$", "field", ")", "]", "[", "0", "]", ";", "$", "courseupdated", "=", "true", ";", "}", "}", "if", "(", "!", "$", "courseupdated", ")", "{", "$", "trace", "->", "output", "(", "get_string", "(", "'courseupdateskipped'", ",", "'enrol_ldap'", ",", "$", "course", ")", ")", ";", "return", "false", ";", "}", "// Do not allow empty fullname or shortname.", "if", "(", "(", "isset", "(", "$", "updatedcourse", "->", "fullname", ")", "&&", "empty", "(", "$", "updatedcourse", "->", "fullname", ")", ")", "||", "(", "isset", "(", "$", "updatedcourse", "->", "shortname", ")", "&&", "empty", "(", "$", "updatedcourse", "->", "shortname", ")", ")", ")", "{", "// We are in trouble!", "$", "trace", "->", "output", "(", "get_string", "(", "'cannotupdatecourse'", ",", "'enrol_ldap'", ",", "$", "course", ")", ")", ";", "return", "false", ";", "}", "// Check if the shortname already exists if it does - skip course updating.", "if", "(", "isset", "(", "$", "updatedcourse", "->", "shortname", ")", "&&", "$", "DB", "->", "record_exists", "(", "'course'", ",", "array", "(", "'shortname'", "=>", "$", "updatedcourse", "->", "shortname", ")", ")", ")", "{", "$", "trace", "->", "output", "(", "get_string", "(", "'cannotupdatecourse_duplicateshortname'", ",", "'enrol_ldap'", ",", "$", "course", ")", ")", ";", "return", "false", ";", "}", "// Finally - update course in DB.", "update_course", "(", "$", "updatedcourse", ")", ";", "$", "trace", "->", "output", "(", "get_string", "(", "'courseupdated'", ",", "'enrol_ldap'", ",", "$", "course", ")", ")", ";", "return", "true", ";", "}" ]
Will update a moodle course with new values from LDAP A field will be updated only if it is marked to be updated on sync in plugin settings @param object $course @param array $externalcourse @param progress_trace $trace @return bool
[ "Will", "update", "a", "moodle", "course", "with", "new", "values", "from", "LDAP", "A", "field", "will", "be", "updated", "only", "if", "it", "is", "marked", "to", "be", "updated", "on", "sync", "in", "plugin", "settings" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/enrol/ldap/lib.php#L1035-L1095
212,323
moodle/moodle
lib/typo3/class.t3lib_cs.php
t3lib_cs.parse_charset
function parse_charset($charset) { $charset = trim(strtolower($charset)); if (isset($this->synonyms[$charset])) { $charset = $this->synonyms[$charset]; } return $charset; }
php
function parse_charset($charset) { $charset = trim(strtolower($charset)); if (isset($this->synonyms[$charset])) { $charset = $this->synonyms[$charset]; } return $charset; }
[ "function", "parse_charset", "(", "$", "charset", ")", "{", "$", "charset", "=", "trim", "(", "strtolower", "(", "$", "charset", ")", ")", ";", "if", "(", "isset", "(", "$", "this", "->", "synonyms", "[", "$", "charset", "]", ")", ")", "{", "$", "charset", "=", "$", "this", "->", "synonyms", "[", "$", "charset", "]", ";", "}", "return", "$", "charset", ";", "}" ]
Normalize - changes input character set to lowercase letters. @param string Input charset @return string Normalized charset @author Martin Kutschker <martin.t.kutschker@blackbox.net>
[ "Normalize", "-", "changes", "input", "character", "set", "to", "lowercase", "letters", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/typo3/class.t3lib_cs.php#L523-L530
212,324
moodle/moodle
lib/typo3/class.t3lib_cs.php
t3lib_cs.get_locale_charset
function get_locale_charset($locale) { $locale = strtolower($locale); // exact locale specific charset? if (isset($this->locale_to_charset[$locale])) { return $this->locale_to_charset[$locale]; } // get modifier list($locale, $modifier) = explode('@', $locale); // locale contains charset: use it list($locale, $charset) = explode('.', $locale); if ($charset) { return $this->parse_charset($charset); } // modifier is 'euro' (after charset check, because of xx.utf-8@euro) if ($modifier == 'euro') { return 'iso-8859-15'; } // get language list($language, $country) = explode('_', $locale); if (isset($this->lang_to_script[$language])) { $script = $this->lang_to_script[$language]; } if (TYPO3_OS == 'WIN') { $cs = $this->script_to_charset_windows[$script] ? $this->script_to_charset_windows[$script] : 'windows-1252'; } else { $cs = $this->script_to_charset_unix[$script] ? $this->script_to_charset_unix[$script] : 'utf-8'; } return $cs; }
php
function get_locale_charset($locale) { $locale = strtolower($locale); // exact locale specific charset? if (isset($this->locale_to_charset[$locale])) { return $this->locale_to_charset[$locale]; } // get modifier list($locale, $modifier) = explode('@', $locale); // locale contains charset: use it list($locale, $charset) = explode('.', $locale); if ($charset) { return $this->parse_charset($charset); } // modifier is 'euro' (after charset check, because of xx.utf-8@euro) if ($modifier == 'euro') { return 'iso-8859-15'; } // get language list($language, $country) = explode('_', $locale); if (isset($this->lang_to_script[$language])) { $script = $this->lang_to_script[$language]; } if (TYPO3_OS == 'WIN') { $cs = $this->script_to_charset_windows[$script] ? $this->script_to_charset_windows[$script] : 'windows-1252'; } else { $cs = $this->script_to_charset_unix[$script] ? $this->script_to_charset_unix[$script] : 'utf-8'; } return $cs; }
[ "function", "get_locale_charset", "(", "$", "locale", ")", "{", "$", "locale", "=", "strtolower", "(", "$", "locale", ")", ";", "// exact locale specific charset?", "if", "(", "isset", "(", "$", "this", "->", "locale_to_charset", "[", "$", "locale", "]", ")", ")", "{", "return", "$", "this", "->", "locale_to_charset", "[", "$", "locale", "]", ";", "}", "// get modifier", "list", "(", "$", "locale", ",", "$", "modifier", ")", "=", "explode", "(", "'@'", ",", "$", "locale", ")", ";", "// locale contains charset: use it", "list", "(", "$", "locale", ",", "$", "charset", ")", "=", "explode", "(", "'.'", ",", "$", "locale", ")", ";", "if", "(", "$", "charset", ")", "{", "return", "$", "this", "->", "parse_charset", "(", "$", "charset", ")", ";", "}", "// modifier is 'euro' (after charset check, because of xx.utf-8@euro)", "if", "(", "$", "modifier", "==", "'euro'", ")", "{", "return", "'iso-8859-15'", ";", "}", "// get language", "list", "(", "$", "language", ",", "$", "country", ")", "=", "explode", "(", "'_'", ",", "$", "locale", ")", ";", "if", "(", "isset", "(", "$", "this", "->", "lang_to_script", "[", "$", "language", "]", ")", ")", "{", "$", "script", "=", "$", "this", "->", "lang_to_script", "[", "$", "language", "]", ";", "}", "if", "(", "TYPO3_OS", "==", "'WIN'", ")", "{", "$", "cs", "=", "$", "this", "->", "script_to_charset_windows", "[", "$", "script", "]", "?", "$", "this", "->", "script_to_charset_windows", "[", "$", "script", "]", ":", "'windows-1252'", ";", "}", "else", "{", "$", "cs", "=", "$", "this", "->", "script_to_charset_unix", "[", "$", "script", "]", "?", "$", "this", "->", "script_to_charset_unix", "[", "$", "script", "]", ":", "'utf-8'", ";", "}", "return", "$", "cs", ";", "}" ]
Get the charset of a locale. ln language ln_CN language / country ln_CN.cs language / country / charset ln_CN.cs@mod language / country / charset / modifier @param string Locale string @return string Charset resolved for locale string @author Martin Kutschker <martin.t.kutschker@blackbox.net>
[ "Get", "the", "charset", "of", "a", "locale", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/typo3/class.t3lib_cs.php#L544-L579
212,325
moodle/moodle
lib/typo3/class.t3lib_cs.php
t3lib_cs.conv
function conv($str, $fromCS, $toCS, $useEntityForNoChar = 0) { if ($fromCS == $toCS) { return $str; } // PHP-libs don't support fallback to SGML entities, but UTF-8 handles everything if ($toCS == 'utf-8' || !$useEntityForNoChar) { switch ($GLOBALS['TYPO3_CONF_VARS']['SYS']['t3lib_cs_convMethod']) { case 'mbstring': $conv_str = mb_convert_encoding($str, $toCS, $fromCS); if (FALSE !== $conv_str) { return $conv_str; } // returns FALSE for unsupported charsets break; case 'iconv': $conv_str = iconv($fromCS, $toCS . '//TRANSLIT', $str); if (FALSE !== $conv_str) { return $conv_str; } break; case 'recode': $conv_str = recode_string($fromCS . '..' . $toCS, $str); if (FALSE !== $conv_str) { return $conv_str; } break; } // fallback to TYPO3 conversion } if ($fromCS != 'utf-8') { $str = $this->utf8_encode($str, $fromCS); } if ($toCS != 'utf-8') { $str = $this->utf8_decode($str, $toCS, $useEntityForNoChar); } return $str; }
php
function conv($str, $fromCS, $toCS, $useEntityForNoChar = 0) { if ($fromCS == $toCS) { return $str; } // PHP-libs don't support fallback to SGML entities, but UTF-8 handles everything if ($toCS == 'utf-8' || !$useEntityForNoChar) { switch ($GLOBALS['TYPO3_CONF_VARS']['SYS']['t3lib_cs_convMethod']) { case 'mbstring': $conv_str = mb_convert_encoding($str, $toCS, $fromCS); if (FALSE !== $conv_str) { return $conv_str; } // returns FALSE for unsupported charsets break; case 'iconv': $conv_str = iconv($fromCS, $toCS . '//TRANSLIT', $str); if (FALSE !== $conv_str) { return $conv_str; } break; case 'recode': $conv_str = recode_string($fromCS . '..' . $toCS, $str); if (FALSE !== $conv_str) { return $conv_str; } break; } // fallback to TYPO3 conversion } if ($fromCS != 'utf-8') { $str = $this->utf8_encode($str, $fromCS); } if ($toCS != 'utf-8') { $str = $this->utf8_decode($str, $toCS, $useEntityForNoChar); } return $str; }
[ "function", "conv", "(", "$", "str", ",", "$", "fromCS", ",", "$", "toCS", ",", "$", "useEntityForNoChar", "=", "0", ")", "{", "if", "(", "$", "fromCS", "==", "$", "toCS", ")", "{", "return", "$", "str", ";", "}", "// PHP-libs don't support fallback to SGML entities, but UTF-8 handles everything", "if", "(", "$", "toCS", "==", "'utf-8'", "||", "!", "$", "useEntityForNoChar", ")", "{", "switch", "(", "$", "GLOBALS", "[", "'TYPO3_CONF_VARS'", "]", "[", "'SYS'", "]", "[", "'t3lib_cs_convMethod'", "]", ")", "{", "case", "'mbstring'", ":", "$", "conv_str", "=", "mb_convert_encoding", "(", "$", "str", ",", "$", "toCS", ",", "$", "fromCS", ")", ";", "if", "(", "FALSE", "!==", "$", "conv_str", ")", "{", "return", "$", "conv_str", ";", "}", "// returns FALSE for unsupported charsets", "break", ";", "case", "'iconv'", ":", "$", "conv_str", "=", "iconv", "(", "$", "fromCS", ",", "$", "toCS", ".", "'//TRANSLIT'", ",", "$", "str", ")", ";", "if", "(", "FALSE", "!==", "$", "conv_str", ")", "{", "return", "$", "conv_str", ";", "}", "break", ";", "case", "'recode'", ":", "$", "conv_str", "=", "recode_string", "(", "$", "fromCS", ".", "'..'", ".", "$", "toCS", ",", "$", "str", ")", ";", "if", "(", "FALSE", "!==", "$", "conv_str", ")", "{", "return", "$", "conv_str", ";", "}", "break", ";", "}", "// fallback to TYPO3 conversion", "}", "if", "(", "$", "fromCS", "!=", "'utf-8'", ")", "{", "$", "str", "=", "$", "this", "->", "utf8_encode", "(", "$", "str", ",", "$", "fromCS", ")", ";", "}", "if", "(", "$", "toCS", "!=", "'utf-8'", ")", "{", "$", "str", "=", "$", "this", "->", "utf8_decode", "(", "$", "str", ",", "$", "toCS", ",", "$", "useEntityForNoChar", ")", ";", "}", "return", "$", "str", ";", "}" ]
Convert from one charset to another charset. @param string Input string @param string From charset (the current charset of the string) @param string To charset (the output charset wanted) @param boolean If set, then characters that are not available in the destination character set will be encoded as numeric entities @return string Converted string @see convArray()
[ "Convert", "from", "one", "charset", "to", "another", "charset", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/typo3/class.t3lib_cs.php#L598-L637
212,326
moodle/moodle
lib/typo3/class.t3lib_cs.php
t3lib_cs.utf8_to_entities
function utf8_to_entities($str) { $strLen = strlen($str); $outStr = ''; $buf = ''; for ($a = 0; $a < $strLen; $a++) { // Traverse each char in UTF-8 string. $chr = substr($str, $a, 1); $ord = ord($chr); if ($ord > 127) { // This means multibyte! (first byte!) if ($ord & 64) { // Since the first byte must have the 7th bit set we check that. Otherwise we might be in the middle of a byte sequence. $buf = $chr; // Add first byte for ($b = 0; $b < 8; $b++) { // for each byte in multibyte string... $ord = $ord << 1; // Shift it left and ... if ($ord & 128) { // ... and with 8th bit - if that is set, then there are still bytes in sequence. $a++; // Increase pointer... $buf .= substr($str, $a, 1); // ... and add the next char. } else { break; } } $outStr .= '&#' . $this->utf8CharToUnumber($buf, 1) . ';'; } else { $outStr .= chr($this->noCharByteVal); } // No char exists (MIDDLE of MB sequence!) } else { $outStr .= $chr; } // ... otherwise it's just ASCII 0-127 and one byte. Transparent } return $outStr; }
php
function utf8_to_entities($str) { $strLen = strlen($str); $outStr = ''; $buf = ''; for ($a = 0; $a < $strLen; $a++) { // Traverse each char in UTF-8 string. $chr = substr($str, $a, 1); $ord = ord($chr); if ($ord > 127) { // This means multibyte! (first byte!) if ($ord & 64) { // Since the first byte must have the 7th bit set we check that. Otherwise we might be in the middle of a byte sequence. $buf = $chr; // Add first byte for ($b = 0; $b < 8; $b++) { // for each byte in multibyte string... $ord = $ord << 1; // Shift it left and ... if ($ord & 128) { // ... and with 8th bit - if that is set, then there are still bytes in sequence. $a++; // Increase pointer... $buf .= substr($str, $a, 1); // ... and add the next char. } else { break; } } $outStr .= '&#' . $this->utf8CharToUnumber($buf, 1) . ';'; } else { $outStr .= chr($this->noCharByteVal); } // No char exists (MIDDLE of MB sequence!) } else { $outStr .= $chr; } // ... otherwise it's just ASCII 0-127 and one byte. Transparent } return $outStr; }
[ "function", "utf8_to_entities", "(", "$", "str", ")", "{", "$", "strLen", "=", "strlen", "(", "$", "str", ")", ";", "$", "outStr", "=", "''", ";", "$", "buf", "=", "''", ";", "for", "(", "$", "a", "=", "0", ";", "$", "a", "<", "$", "strLen", ";", "$", "a", "++", ")", "{", "// Traverse each char in UTF-8 string.", "$", "chr", "=", "substr", "(", "$", "str", ",", "$", "a", ",", "1", ")", ";", "$", "ord", "=", "ord", "(", "$", "chr", ")", ";", "if", "(", "$", "ord", ">", "127", ")", "{", "// This means multibyte! (first byte!)", "if", "(", "$", "ord", "&", "64", ")", "{", "// Since the first byte must have the 7th bit set we check that. Otherwise we might be in the middle of a byte sequence.", "$", "buf", "=", "$", "chr", ";", "// Add first byte", "for", "(", "$", "b", "=", "0", ";", "$", "b", "<", "8", ";", "$", "b", "++", ")", "{", "// for each byte in multibyte string...", "$", "ord", "=", "$", "ord", "<<", "1", ";", "// Shift it left and ...", "if", "(", "$", "ord", "&", "128", ")", "{", "// ... and with 8th bit - if that is set, then there are still bytes in sequence.", "$", "a", "++", ";", "// Increase pointer...", "$", "buf", ".=", "substr", "(", "$", "str", ",", "$", "a", ",", "1", ")", ";", "// ... and add the next char.", "}", "else", "{", "break", ";", "}", "}", "$", "outStr", ".=", "'&#'", ".", "$", "this", "->", "utf8CharToUnumber", "(", "$", "buf", ",", "1", ")", ".", "';'", ";", "}", "else", "{", "$", "outStr", ".=", "chr", "(", "$", "this", "->", "noCharByteVal", ")", ";", "}", "// No char exists (MIDDLE of MB sequence!)", "}", "else", "{", "$", "outStr", ".=", "$", "chr", ";", "}", "// ... otherwise it's just ASCII 0-127 and one byte. Transparent", "}", "return", "$", "outStr", ";", "}" ]
Converts all chars > 127 to numeric entities. @param string Input string @return string Output string
[ "Converts", "all", "chars", ">", "127", "to", "numeric", "entities", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/typo3/class.t3lib_cs.php#L778-L808
212,327
moodle/moodle
lib/typo3/class.t3lib_cs.php
t3lib_cs.utf8_to_numberarray
function utf8_to_numberarray($str, $convEntities = 0, $retChar = 0) { // If entities must be registered as well...: if ($convEntities) { $str = $this->entities_to_utf8($str, 1); } // Do conversion: $strLen = strlen($str); $outArr = array(); $buf = ''; for ($a = 0; $a < $strLen; $a++) { // Traverse each char in UTF-8 string. $chr = substr($str, $a, 1); $ord = ord($chr); if ($ord > 127) { // This means multibyte! (first byte!) if ($ord & 64) { // Since the first byte must have the 7th bit set we check that. Otherwise we might be in the middle of a byte sequence. $buf = $chr; // Add first byte for ($b = 0; $b < 8; $b++) { // for each byte in multibyte string... $ord = $ord << 1; // Shift it left and ... if ($ord & 128) { // ... and with 8th bit - if that is set, then there are still bytes in sequence. $a++; // Increase pointer... $buf .= substr($str, $a, 1); // ... and add the next char. } else { break; } } $outArr[] = $retChar ? $buf : $this->utf8CharToUnumber($buf); } else { $outArr[] = $retChar ? chr($this->noCharByteVal) : $this->noCharByteVal; } // No char exists (MIDDLE of MB sequence!) } else { $outArr[] = $retChar ? chr($ord) : $ord; } // ... otherwise it's just ASCII 0-127 and one byte. Transparent } return $outArr; }
php
function utf8_to_numberarray($str, $convEntities = 0, $retChar = 0) { // If entities must be registered as well...: if ($convEntities) { $str = $this->entities_to_utf8($str, 1); } // Do conversion: $strLen = strlen($str); $outArr = array(); $buf = ''; for ($a = 0; $a < $strLen; $a++) { // Traverse each char in UTF-8 string. $chr = substr($str, $a, 1); $ord = ord($chr); if ($ord > 127) { // This means multibyte! (first byte!) if ($ord & 64) { // Since the first byte must have the 7th bit set we check that. Otherwise we might be in the middle of a byte sequence. $buf = $chr; // Add first byte for ($b = 0; $b < 8; $b++) { // for each byte in multibyte string... $ord = $ord << 1; // Shift it left and ... if ($ord & 128) { // ... and with 8th bit - if that is set, then there are still bytes in sequence. $a++; // Increase pointer... $buf .= substr($str, $a, 1); // ... and add the next char. } else { break; } } $outArr[] = $retChar ? $buf : $this->utf8CharToUnumber($buf); } else { $outArr[] = $retChar ? chr($this->noCharByteVal) : $this->noCharByteVal; } // No char exists (MIDDLE of MB sequence!) } else { $outArr[] = $retChar ? chr($ord) : $ord; } // ... otherwise it's just ASCII 0-127 and one byte. Transparent } return $outArr; }
[ "function", "utf8_to_numberarray", "(", "$", "str", ",", "$", "convEntities", "=", "0", ",", "$", "retChar", "=", "0", ")", "{", "// If entities must be registered as well...:", "if", "(", "$", "convEntities", ")", "{", "$", "str", "=", "$", "this", "->", "entities_to_utf8", "(", "$", "str", ",", "1", ")", ";", "}", "// Do conversion:", "$", "strLen", "=", "strlen", "(", "$", "str", ")", ";", "$", "outArr", "=", "array", "(", ")", ";", "$", "buf", "=", "''", ";", "for", "(", "$", "a", "=", "0", ";", "$", "a", "<", "$", "strLen", ";", "$", "a", "++", ")", "{", "// Traverse each char in UTF-8 string.", "$", "chr", "=", "substr", "(", "$", "str", ",", "$", "a", ",", "1", ")", ";", "$", "ord", "=", "ord", "(", "$", "chr", ")", ";", "if", "(", "$", "ord", ">", "127", ")", "{", "// This means multibyte! (first byte!)", "if", "(", "$", "ord", "&", "64", ")", "{", "// Since the first byte must have the 7th bit set we check that. Otherwise we might be in the middle of a byte sequence.", "$", "buf", "=", "$", "chr", ";", "// Add first byte", "for", "(", "$", "b", "=", "0", ";", "$", "b", "<", "8", ";", "$", "b", "++", ")", "{", "// for each byte in multibyte string...", "$", "ord", "=", "$", "ord", "<<", "1", ";", "// Shift it left and ...", "if", "(", "$", "ord", "&", "128", ")", "{", "// ... and with 8th bit - if that is set, then there are still bytes in sequence.", "$", "a", "++", ";", "// Increase pointer...", "$", "buf", ".=", "substr", "(", "$", "str", ",", "$", "a", ",", "1", ")", ";", "// ... and add the next char.", "}", "else", "{", "break", ";", "}", "}", "$", "outArr", "[", "]", "=", "$", "retChar", "?", "$", "buf", ":", "$", "this", "->", "utf8CharToUnumber", "(", "$", "buf", ")", ";", "}", "else", "{", "$", "outArr", "[", "]", "=", "$", "retChar", "?", "chr", "(", "$", "this", "->", "noCharByteVal", ")", ":", "$", "this", "->", "noCharByteVal", ";", "}", "// No char exists (MIDDLE of MB sequence!)", "}", "else", "{", "$", "outArr", "[", "]", "=", "$", "retChar", "?", "chr", "(", "$", "ord", ")", ":", "$", "ord", ";", "}", "// ... otherwise it's just ASCII 0-127 and one byte. Transparent", "}", "return", "$", "outArr", ";", "}" ]
Converts all chars in the input UTF-8 string into integer numbers returned in an array @param string Input string, UTF-8 @param boolean If set, then all HTML entities (like &amp; or &pound; or &#123; or &#x3f5d;) will be detected as characters. @param boolean If set, then instead of integer numbers the real UTF-8 char is returned. @return array Output array with the char numbers
[ "Converts", "all", "chars", "in", "the", "input", "UTF", "-", "8", "string", "into", "integer", "numbers", "returned", "in", "an", "array" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/typo3/class.t3lib_cs.php#L869-L904
212,328
moodle/moodle
lib/typo3/class.t3lib_cs.php
t3lib_cs.utf8CharToUnumber
function utf8CharToUnumber($str, $hex = 0) { $ord = ord(substr($str, 0, 1)); // First char if (($ord & 192) == 192) { // This verifyes that it IS a multi byte string $binBuf = ''; for ($b = 0; $b < 8; $b++) { // for each byte in multibyte string... $ord = $ord << 1; // Shift it left and ... if ($ord & 128) { // ... and with 8th bit - if that is set, then there are still bytes in sequence. $binBuf .= substr('00000000' . decbin(ord(substr($str, $b + 1, 1))), -6); } else { break; } } $binBuf = substr('00000000' . decbin(ord(substr($str, 0, 1))), -(6 - $b)) . $binBuf; $int = bindec($binBuf); } else { $int = $ord; } return $hex ? 'x' . dechex($int) : $int; }
php
function utf8CharToUnumber($str, $hex = 0) { $ord = ord(substr($str, 0, 1)); // First char if (($ord & 192) == 192) { // This verifyes that it IS a multi byte string $binBuf = ''; for ($b = 0; $b < 8; $b++) { // for each byte in multibyte string... $ord = $ord << 1; // Shift it left and ... if ($ord & 128) { // ... and with 8th bit - if that is set, then there are still bytes in sequence. $binBuf .= substr('00000000' . decbin(ord(substr($str, $b + 1, 1))), -6); } else { break; } } $binBuf = substr('00000000' . decbin(ord(substr($str, 0, 1))), -(6 - $b)) . $binBuf; $int = bindec($binBuf); } else { $int = $ord; } return $hex ? 'x' . dechex($int) : $int; }
[ "function", "utf8CharToUnumber", "(", "$", "str", ",", "$", "hex", "=", "0", ")", "{", "$", "ord", "=", "ord", "(", "substr", "(", "$", "str", ",", "0", ",", "1", ")", ")", ";", "// First char", "if", "(", "(", "$", "ord", "&", "192", ")", "==", "192", ")", "{", "// This verifyes that it IS a multi byte string", "$", "binBuf", "=", "''", ";", "for", "(", "$", "b", "=", "0", ";", "$", "b", "<", "8", ";", "$", "b", "++", ")", "{", "// for each byte in multibyte string...", "$", "ord", "=", "$", "ord", "<<", "1", ";", "// Shift it left and ...", "if", "(", "$", "ord", "&", "128", ")", "{", "// ... and with 8th bit - if that is set, then there are still bytes in sequence.", "$", "binBuf", ".=", "substr", "(", "'00000000'", ".", "decbin", "(", "ord", "(", "substr", "(", "$", "str", ",", "$", "b", "+", "1", ",", "1", ")", ")", ")", ",", "-", "6", ")", ";", "}", "else", "{", "break", ";", "}", "}", "$", "binBuf", "=", "substr", "(", "'00000000'", ".", "decbin", "(", "ord", "(", "substr", "(", "$", "str", ",", "0", ",", "1", ")", ")", ")", ",", "-", "(", "6", "-", "$", "b", ")", ")", ".", "$", "binBuf", ";", "$", "int", "=", "bindec", "(", "$", "binBuf", ")", ";", "}", "else", "{", "$", "int", "=", "$", "ord", ";", "}", "return", "$", "hex", "?", "'x'", ".", "dechex", "(", "$", "int", ")", ":", "$", "int", ";", "}" ]
Converts a UTF-8 Multibyte character to a UNICODE number Unit-tested by Kasper @param string UTF-8 multibyte character string @param boolean If set, then a hex. number is returned. @return integer UNICODE integer @see UnumberToChar()
[ "Converts", "a", "UTF", "-", "8", "Multibyte", "character", "to", "a", "UNICODE", "number", "Unit", "-", "tested", "by", "Kasper" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/typo3/class.t3lib_cs.php#L980-L1001
212,329
moodle/moodle
lib/typo3/class.t3lib_cs.php
t3lib_cs.initCaseFolding
function initCaseFolding($charset) { // Only process if the case table is not yet loaded: if (is_array($this->caseFolding[$charset])) { return 1; } // Use cached version if possible $cacheFile = t3lib_div::getFileAbsFileName('typo3temp/cs/cscase_' . $charset . '.tbl'); if ($cacheFile && @is_file($cacheFile)) { $this->caseFolding[$charset] = unserialize(t3lib_div::getUrl($cacheFile)); return 2; } // init UTF-8 conversion for this charset if (!$this->initCharset($charset)) { return FALSE; } // UTF-8 case folding is used as the base conversion table if (!$this->initUnicodeData('case')) { return FALSE; } $nochar = chr($this->noCharByteVal); foreach ($this->parsedCharsets[$charset]['local'] as $ci => $utf8) { // reconvert to charset (don't use chr() of numeric value, might be muli-byte) $c = $this->utf8_decode($utf8, $charset); // $cc = $this->conv($this->caseFolding['utf-8']['toUpper'][$utf8], 'utf-8', $charset); $cc = $this->utf8_decode($this->caseFolding['utf-8']['toUpper'][$utf8], $charset); if ($cc != '' && $cc != $nochar) { $this->caseFolding[$charset]['toUpper'][$c] = $cc; } // $cc = $this->conv($this->caseFolding['utf-8']['toLower'][$utf8], 'utf-8', $charset); $cc = $this->utf8_decode($this->caseFolding['utf-8']['toLower'][$utf8], $charset); if ($cc != '' && $cc != $nochar) { $this->caseFolding[$charset]['toLower'][$c] = $cc; } // $cc = $this->conv($this->caseFolding['utf-8']['toTitle'][$utf8], 'utf-8', $charset); $cc = $this->utf8_decode($this->caseFolding['utf-8']['toTitle'][$utf8], $charset); if ($cc != '' && $cc != $nochar) { $this->caseFolding[$charset]['toTitle'][$c] = $cc; } } // add the ASCII case table for ($i = ord('a'); $i <= ord('z'); $i++) { $this->caseFolding[$charset]['toUpper'][chr($i)] = chr($i - 32); } for ($i = ord('A'); $i <= ord('Z'); $i++) { $this->caseFolding[$charset]['toLower'][chr($i)] = chr($i + 32); } if ($cacheFile) { t3lib_div::writeFileToTypo3tempDir($cacheFile, serialize($this->caseFolding[$charset])); } return 3; }
php
function initCaseFolding($charset) { // Only process if the case table is not yet loaded: if (is_array($this->caseFolding[$charset])) { return 1; } // Use cached version if possible $cacheFile = t3lib_div::getFileAbsFileName('typo3temp/cs/cscase_' . $charset . '.tbl'); if ($cacheFile && @is_file($cacheFile)) { $this->caseFolding[$charset] = unserialize(t3lib_div::getUrl($cacheFile)); return 2; } // init UTF-8 conversion for this charset if (!$this->initCharset($charset)) { return FALSE; } // UTF-8 case folding is used as the base conversion table if (!$this->initUnicodeData('case')) { return FALSE; } $nochar = chr($this->noCharByteVal); foreach ($this->parsedCharsets[$charset]['local'] as $ci => $utf8) { // reconvert to charset (don't use chr() of numeric value, might be muli-byte) $c = $this->utf8_decode($utf8, $charset); // $cc = $this->conv($this->caseFolding['utf-8']['toUpper'][$utf8], 'utf-8', $charset); $cc = $this->utf8_decode($this->caseFolding['utf-8']['toUpper'][$utf8], $charset); if ($cc != '' && $cc != $nochar) { $this->caseFolding[$charset]['toUpper'][$c] = $cc; } // $cc = $this->conv($this->caseFolding['utf-8']['toLower'][$utf8], 'utf-8', $charset); $cc = $this->utf8_decode($this->caseFolding['utf-8']['toLower'][$utf8], $charset); if ($cc != '' && $cc != $nochar) { $this->caseFolding[$charset]['toLower'][$c] = $cc; } // $cc = $this->conv($this->caseFolding['utf-8']['toTitle'][$utf8], 'utf-8', $charset); $cc = $this->utf8_decode($this->caseFolding['utf-8']['toTitle'][$utf8], $charset); if ($cc != '' && $cc != $nochar) { $this->caseFolding[$charset]['toTitle'][$c] = $cc; } } // add the ASCII case table for ($i = ord('a'); $i <= ord('z'); $i++) { $this->caseFolding[$charset]['toUpper'][chr($i)] = chr($i - 32); } for ($i = ord('A'); $i <= ord('Z'); $i++) { $this->caseFolding[$charset]['toLower'][chr($i)] = chr($i + 32); } if ($cacheFile) { t3lib_div::writeFileToTypo3tempDir($cacheFile, serialize($this->caseFolding[$charset])); } return 3; }
[ "function", "initCaseFolding", "(", "$", "charset", ")", "{", "// Only process if the case table is not yet loaded:", "if", "(", "is_array", "(", "$", "this", "->", "caseFolding", "[", "$", "charset", "]", ")", ")", "{", "return", "1", ";", "}", "// Use cached version if possible", "$", "cacheFile", "=", "t3lib_div", "::", "getFileAbsFileName", "(", "'typo3temp/cs/cscase_'", ".", "$", "charset", ".", "'.tbl'", ")", ";", "if", "(", "$", "cacheFile", "&&", "@", "is_file", "(", "$", "cacheFile", ")", ")", "{", "$", "this", "->", "caseFolding", "[", "$", "charset", "]", "=", "unserialize", "(", "t3lib_div", "::", "getUrl", "(", "$", "cacheFile", ")", ")", ";", "return", "2", ";", "}", "// init UTF-8 conversion for this charset", "if", "(", "!", "$", "this", "->", "initCharset", "(", "$", "charset", ")", ")", "{", "return", "FALSE", ";", "}", "// UTF-8 case folding is used as the base conversion table", "if", "(", "!", "$", "this", "->", "initUnicodeData", "(", "'case'", ")", ")", "{", "return", "FALSE", ";", "}", "$", "nochar", "=", "chr", "(", "$", "this", "->", "noCharByteVal", ")", ";", "foreach", "(", "$", "this", "->", "parsedCharsets", "[", "$", "charset", "]", "[", "'local'", "]", "as", "$", "ci", "=>", "$", "utf8", ")", "{", "// reconvert to charset (don't use chr() of numeric value, might be muli-byte)", "$", "c", "=", "$", "this", "->", "utf8_decode", "(", "$", "utf8", ",", "$", "charset", ")", ";", "// $cc = $this->conv($this->caseFolding['utf-8']['toUpper'][$utf8], 'utf-8', $charset);", "$", "cc", "=", "$", "this", "->", "utf8_decode", "(", "$", "this", "->", "caseFolding", "[", "'utf-8'", "]", "[", "'toUpper'", "]", "[", "$", "utf8", "]", ",", "$", "charset", ")", ";", "if", "(", "$", "cc", "!=", "''", "&&", "$", "cc", "!=", "$", "nochar", ")", "{", "$", "this", "->", "caseFolding", "[", "$", "charset", "]", "[", "'toUpper'", "]", "[", "$", "c", "]", "=", "$", "cc", ";", "}", "// $cc = $this->conv($this->caseFolding['utf-8']['toLower'][$utf8], 'utf-8', $charset);", "$", "cc", "=", "$", "this", "->", "utf8_decode", "(", "$", "this", "->", "caseFolding", "[", "'utf-8'", "]", "[", "'toLower'", "]", "[", "$", "utf8", "]", ",", "$", "charset", ")", ";", "if", "(", "$", "cc", "!=", "''", "&&", "$", "cc", "!=", "$", "nochar", ")", "{", "$", "this", "->", "caseFolding", "[", "$", "charset", "]", "[", "'toLower'", "]", "[", "$", "c", "]", "=", "$", "cc", ";", "}", "// $cc = $this->conv($this->caseFolding['utf-8']['toTitle'][$utf8], 'utf-8', $charset);", "$", "cc", "=", "$", "this", "->", "utf8_decode", "(", "$", "this", "->", "caseFolding", "[", "'utf-8'", "]", "[", "'toTitle'", "]", "[", "$", "utf8", "]", ",", "$", "charset", ")", ";", "if", "(", "$", "cc", "!=", "''", "&&", "$", "cc", "!=", "$", "nochar", ")", "{", "$", "this", "->", "caseFolding", "[", "$", "charset", "]", "[", "'toTitle'", "]", "[", "$", "c", "]", "=", "$", "cc", ";", "}", "}", "// add the ASCII case table", "for", "(", "$", "i", "=", "ord", "(", "'a'", ")", ";", "$", "i", "<=", "ord", "(", "'z'", ")", ";", "$", "i", "++", ")", "{", "$", "this", "->", "caseFolding", "[", "$", "charset", "]", "[", "'toUpper'", "]", "[", "chr", "(", "$", "i", ")", "]", "=", "chr", "(", "$", "i", "-", "32", ")", ";", "}", "for", "(", "$", "i", "=", "ord", "(", "'A'", ")", ";", "$", "i", "<=", "ord", "(", "'Z'", ")", ";", "$", "i", "++", ")", "{", "$", "this", "->", "caseFolding", "[", "$", "charset", "]", "[", "'toLower'", "]", "[", "chr", "(", "$", "i", ")", "]", "=", "chr", "(", "$", "i", "+", "32", ")", ";", "}", "if", "(", "$", "cacheFile", ")", "{", "t3lib_div", "::", "writeFileToTypo3tempDir", "(", "$", "cacheFile", ",", "serialize", "(", "$", "this", "->", "caseFolding", "[", "$", "charset", "]", ")", ")", ";", "}", "return", "3", ";", "}" ]
This function initializes the folding table for a charset other than UTF-8. This function is automatically called by the case folding functions. @param string Charset for which to initialize case folding. @return integer Returns FALSE on error, a TRUE value on success: 1 table already loaded, 2, cached version, 3 table parsed (and cached). @access private
[ "This", "function", "initializes", "the", "folding", "table", "for", "a", "charset", "other", "than", "UTF", "-", "8", ".", "This", "function", "is", "automatically", "called", "by", "the", "case", "folding", "functions", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/typo3/class.t3lib_cs.php#L1346-L1406
212,330
moodle/moodle
lib/typo3/class.t3lib_cs.php
t3lib_cs.initToASCII
function initToASCII($charset) { // Only process if the case table is not yet loaded: if (is_array($this->toASCII[$charset])) { return 1; } // Use cached version if possible $cacheFile = t3lib_div::getFileAbsFileName('typo3temp/cs/csascii_' . $charset . '.tbl'); if ($cacheFile && @is_file($cacheFile)) { $this->toASCII[$charset] = unserialize(t3lib_div::getUrl($cacheFile)); return 2; } // init UTF-8 conversion for this charset if (!$this->initCharset($charset)) { return FALSE; } // UTF-8/ASCII transliteration is used as the base conversion table if (!$this->initUnicodeData('ascii')) { return FALSE; } $nochar = chr($this->noCharByteVal); foreach ($this->parsedCharsets[$charset]['local'] as $ci => $utf8) { // reconvert to charset (don't use chr() of numeric value, might be muli-byte) $c = $this->utf8_decode($utf8, $charset); if (isset($this->toASCII['utf-8'][$utf8])) { $this->toASCII[$charset][$c] = $this->toASCII['utf-8'][$utf8]; } } if ($cacheFile) { t3lib_div::writeFileToTypo3tempDir($cacheFile, serialize($this->toASCII[$charset])); } return 3; }
php
function initToASCII($charset) { // Only process if the case table is not yet loaded: if (is_array($this->toASCII[$charset])) { return 1; } // Use cached version if possible $cacheFile = t3lib_div::getFileAbsFileName('typo3temp/cs/csascii_' . $charset . '.tbl'); if ($cacheFile && @is_file($cacheFile)) { $this->toASCII[$charset] = unserialize(t3lib_div::getUrl($cacheFile)); return 2; } // init UTF-8 conversion for this charset if (!$this->initCharset($charset)) { return FALSE; } // UTF-8/ASCII transliteration is used as the base conversion table if (!$this->initUnicodeData('ascii')) { return FALSE; } $nochar = chr($this->noCharByteVal); foreach ($this->parsedCharsets[$charset]['local'] as $ci => $utf8) { // reconvert to charset (don't use chr() of numeric value, might be muli-byte) $c = $this->utf8_decode($utf8, $charset); if (isset($this->toASCII['utf-8'][$utf8])) { $this->toASCII[$charset][$c] = $this->toASCII['utf-8'][$utf8]; } } if ($cacheFile) { t3lib_div::writeFileToTypo3tempDir($cacheFile, serialize($this->toASCII[$charset])); } return 3; }
[ "function", "initToASCII", "(", "$", "charset", ")", "{", "// Only process if the case table is not yet loaded:", "if", "(", "is_array", "(", "$", "this", "->", "toASCII", "[", "$", "charset", "]", ")", ")", "{", "return", "1", ";", "}", "// Use cached version if possible", "$", "cacheFile", "=", "t3lib_div", "::", "getFileAbsFileName", "(", "'typo3temp/cs/csascii_'", ".", "$", "charset", ".", "'.tbl'", ")", ";", "if", "(", "$", "cacheFile", "&&", "@", "is_file", "(", "$", "cacheFile", ")", ")", "{", "$", "this", "->", "toASCII", "[", "$", "charset", "]", "=", "unserialize", "(", "t3lib_div", "::", "getUrl", "(", "$", "cacheFile", ")", ")", ";", "return", "2", ";", "}", "// init UTF-8 conversion for this charset", "if", "(", "!", "$", "this", "->", "initCharset", "(", "$", "charset", ")", ")", "{", "return", "FALSE", ";", "}", "// UTF-8/ASCII transliteration is used as the base conversion table", "if", "(", "!", "$", "this", "->", "initUnicodeData", "(", "'ascii'", ")", ")", "{", "return", "FALSE", ";", "}", "$", "nochar", "=", "chr", "(", "$", "this", "->", "noCharByteVal", ")", ";", "foreach", "(", "$", "this", "->", "parsedCharsets", "[", "$", "charset", "]", "[", "'local'", "]", "as", "$", "ci", "=>", "$", "utf8", ")", "{", "// reconvert to charset (don't use chr() of numeric value, might be muli-byte)", "$", "c", "=", "$", "this", "->", "utf8_decode", "(", "$", "utf8", ",", "$", "charset", ")", ";", "if", "(", "isset", "(", "$", "this", "->", "toASCII", "[", "'utf-8'", "]", "[", "$", "utf8", "]", ")", ")", "{", "$", "this", "->", "toASCII", "[", "$", "charset", "]", "[", "$", "c", "]", "=", "$", "this", "->", "toASCII", "[", "'utf-8'", "]", "[", "$", "utf8", "]", ";", "}", "}", "if", "(", "$", "cacheFile", ")", "{", "t3lib_div", "::", "writeFileToTypo3tempDir", "(", "$", "cacheFile", ",", "serialize", "(", "$", "this", "->", "toASCII", "[", "$", "charset", "]", ")", ")", ";", "}", "return", "3", ";", "}" ]
This function initializes the to-ASCII conversion table for a charset other than UTF-8. This function is automatically called by the ASCII transliteration functions. @param string Charset for which to initialize conversion. @return integer Returns FALSE on error, a TRUE value on success: 1 table already loaded, 2, cached version, 3 table parsed (and cached). @access private
[ "This", "function", "initializes", "the", "to", "-", "ASCII", "conversion", "table", "for", "a", "charset", "other", "than", "UTF", "-", "8", ".", "This", "function", "is", "automatically", "called", "by", "the", "ASCII", "transliteration", "functions", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/typo3/class.t3lib_cs.php#L1416-L1454
212,331
moodle/moodle
lib/typo3/class.t3lib_cs.php
t3lib_cs.cropMbstring
protected function cropMbstring($charset, $string, $len, $crop = '') { if (intval($len) === 0 || mb_strlen($string, $charset) <= abs($len)) { return $string; } if ($len > 0) { $string = mb_substr($string, 0, $len, $charset) . $crop; } else { $string = $crop . mb_substr($string, $len, mb_strlen($string, $charset), $charset); } return $string; }
php
protected function cropMbstring($charset, $string, $len, $crop = '') { if (intval($len) === 0 || mb_strlen($string, $charset) <= abs($len)) { return $string; } if ($len > 0) { $string = mb_substr($string, 0, $len, $charset) . $crop; } else { $string = $crop . mb_substr($string, $len, mb_strlen($string, $charset), $charset); } return $string; }
[ "protected", "function", "cropMbstring", "(", "$", "charset", ",", "$", "string", ",", "$", "len", ",", "$", "crop", "=", "''", ")", "{", "if", "(", "intval", "(", "$", "len", ")", "===", "0", "||", "mb_strlen", "(", "$", "string", ",", "$", "charset", ")", "<=", "abs", "(", "$", "len", ")", ")", "{", "return", "$", "string", ";", "}", "if", "(", "$", "len", ">", "0", ")", "{", "$", "string", "=", "mb_substr", "(", "$", "string", ",", "0", ",", "$", "len", ",", "$", "charset", ")", ".", "$", "crop", ";", "}", "else", "{", "$", "string", "=", "$", "crop", ".", "mb_substr", "(", "$", "string", ",", "$", "len", ",", "mb_strlen", "(", "$", "string", ",", "$", "charset", ")", ",", "$", "charset", ")", ";", "}", "return", "$", "string", ";", "}" ]
Method to crop strings using the mb_substr function. @param string The character set @param string String to be cropped @param integer Crop length (in characters) @param string Crop signifier @return string The shortened string @see mb_strlen(), mb_substr()
[ "Method", "to", "crop", "strings", "using", "the", "mb_substr", "function", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/typo3/class.t3lib_cs.php#L1558-L1570
212,332
moodle/moodle
lib/typo3/class.t3lib_cs.php
t3lib_cs.strtrunc
function strtrunc($charset, $string, $len) { if ($len <= 0) { return ''; } if ($GLOBALS['TYPO3_CONF_VARS']['SYS']['t3lib_cs_utils'] == 'mbstring') { return mb_strcut($string, 0, $len, $charset); } elseif ($charset == 'utf-8') { return $this->utf8_strtrunc($string, $len); } elseif ($this->eucBasedSets[$charset]) { return $this->euc_strtrunc($string, $len, $charset); } elseif ($this->twoByteSets[$charset]) { if ($len % 2) { $len--; } // don't cut at odd positions } elseif ($this->fourByteSets[$charset]) { $x = $len % 4; $len -= $x; // realign to position dividable by four } // treat everything else as single-byte encoding return substr($string, 0, $len); }
php
function strtrunc($charset, $string, $len) { if ($len <= 0) { return ''; } if ($GLOBALS['TYPO3_CONF_VARS']['SYS']['t3lib_cs_utils'] == 'mbstring') { return mb_strcut($string, 0, $len, $charset); } elseif ($charset == 'utf-8') { return $this->utf8_strtrunc($string, $len); } elseif ($this->eucBasedSets[$charset]) { return $this->euc_strtrunc($string, $len, $charset); } elseif ($this->twoByteSets[$charset]) { if ($len % 2) { $len--; } // don't cut at odd positions } elseif ($this->fourByteSets[$charset]) { $x = $len % 4; $len -= $x; // realign to position dividable by four } // treat everything else as single-byte encoding return substr($string, 0, $len); }
[ "function", "strtrunc", "(", "$", "charset", ",", "$", "string", ",", "$", "len", ")", "{", "if", "(", "$", "len", "<=", "0", ")", "{", "return", "''", ";", "}", "if", "(", "$", "GLOBALS", "[", "'TYPO3_CONF_VARS'", "]", "[", "'SYS'", "]", "[", "'t3lib_cs_utils'", "]", "==", "'mbstring'", ")", "{", "return", "mb_strcut", "(", "$", "string", ",", "0", ",", "$", "len", ",", "$", "charset", ")", ";", "}", "elseif", "(", "$", "charset", "==", "'utf-8'", ")", "{", "return", "$", "this", "->", "utf8_strtrunc", "(", "$", "string", ",", "$", "len", ")", ";", "}", "elseif", "(", "$", "this", "->", "eucBasedSets", "[", "$", "charset", "]", ")", "{", "return", "$", "this", "->", "euc_strtrunc", "(", "$", "string", ",", "$", "len", ",", "$", "charset", ")", ";", "}", "elseif", "(", "$", "this", "->", "twoByteSets", "[", "$", "charset", "]", ")", "{", "if", "(", "$", "len", "%", "2", ")", "{", "$", "len", "--", ";", "}", "// don't cut at odd positions", "}", "elseif", "(", "$", "this", "->", "fourByteSets", "[", "$", "charset", "]", ")", "{", "$", "x", "=", "$", "len", "%", "4", ";", "$", "len", "-=", "$", "x", ";", "// realign to position dividable by four", "}", "// treat everything else as single-byte encoding", "return", "substr", "(", "$", "string", ",", "0", ",", "$", "len", ")", ";", "}" ]
Cuts a string short at a given byte length. @param string The character set @param string Character string @param integer The byte length @return string The shortened string @see mb_strcut() @author Martin Kutschker <martin.t.kutschker@blackbox.net>
[ "Cuts", "a", "string", "short", "at", "a", "given", "byte", "length", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/typo3/class.t3lib_cs.php#L1645-L1666
212,333
moodle/moodle
lib/typo3/class.t3lib_cs.php
t3lib_cs.sb_char_mapping
function sb_char_mapping($str, $charset, $mode, $opt = '') { switch ($mode) { case 'case': if (!$this->initCaseFolding($charset)) { return $str; } // do nothing $map =& $this->caseFolding[$charset][$opt]; break; case 'ascii': if (!$this->initToASCII($charset)) { return $str; } // do nothing $map =& $this->toASCII[$charset]; break; default: return $str; } $out = ''; for ($i = 0; strlen($str{$i}); $i++) { $c = $str{$i}; if (isset($map[$c])) { $out .= $map[$c]; } else { $out .= $c; } } return $out; }
php
function sb_char_mapping($str, $charset, $mode, $opt = '') { switch ($mode) { case 'case': if (!$this->initCaseFolding($charset)) { return $str; } // do nothing $map =& $this->caseFolding[$charset][$opt]; break; case 'ascii': if (!$this->initToASCII($charset)) { return $str; } // do nothing $map =& $this->toASCII[$charset]; break; default: return $str; } $out = ''; for ($i = 0; strlen($str{$i}); $i++) { $c = $str{$i}; if (isset($map[$c])) { $out .= $map[$c]; } else { $out .= $c; } } return $out; }
[ "function", "sb_char_mapping", "(", "$", "str", ",", "$", "charset", ",", "$", "mode", ",", "$", "opt", "=", "''", ")", "{", "switch", "(", "$", "mode", ")", "{", "case", "'case'", ":", "if", "(", "!", "$", "this", "->", "initCaseFolding", "(", "$", "charset", ")", ")", "{", "return", "$", "str", ";", "}", "// do nothing", "$", "map", "=", "&", "$", "this", "->", "caseFolding", "[", "$", "charset", "]", "[", "$", "opt", "]", ";", "break", ";", "case", "'ascii'", ":", "if", "(", "!", "$", "this", "->", "initToASCII", "(", "$", "charset", ")", ")", "{", "return", "$", "str", ";", "}", "// do nothing", "$", "map", "=", "&", "$", "this", "->", "toASCII", "[", "$", "charset", "]", ";", "break", ";", "default", ":", "return", "$", "str", ";", "}", "$", "out", "=", "''", ";", "for", "(", "$", "i", "=", "0", ";", "strlen", "(", "$", "str", "{", "$", "i", "}", ")", ";", "$", "i", "++", ")", "{", "$", "c", "=", "$", "str", "{", "$", "i", "}", ";", "if", "(", "isset", "(", "$", "map", "[", "$", "c", "]", ")", ")", "{", "$", "out", ".=", "$", "map", "[", "$", "c", "]", ";", "}", "else", "{", "$", "out", ".=", "$", "c", ";", "}", "}", "return", "$", "out", ";", "}" ]
Maps all characters of a string in a single byte charset. @param string the string @param string the charset @param string mode: 'case' (case folding) or 'ascii' (ASCII transliteration) @param string 'case': conversion 'toLower' or 'toUpper' @return string the converted string @author Martin Kutschker <martin.t.kutschker@blackbox.net>
[ "Maps", "all", "characters", "of", "a", "string", "in", "a", "single", "byte", "charset", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/typo3/class.t3lib_cs.php#L1817-L1848
212,334
moodle/moodle
lib/typo3/class.t3lib_cs.php
t3lib_cs.utf8_strtrunc
function utf8_strtrunc($str, $len) { $i = $len - 1; if (ord($str{$i}) & 0x80) { // part of a multibyte sequence for (; $i > 0 && !(ord($str{$i}) & 0x40); $i--) { // find the first byte ; } if ($i <= 0) { return ''; } // sanity check for ($bc = 0, $mbs = ord($str{$i}); $mbs & 0x80; $mbs = $mbs << 1) { // calculate number of bytes $bc++; } if ($bc + $i > $len) { return substr($str, 0, $i); } // fallthru: multibyte char fits into length } return substr($str, 0, $len); }
php
function utf8_strtrunc($str, $len) { $i = $len - 1; if (ord($str{$i}) & 0x80) { // part of a multibyte sequence for (; $i > 0 && !(ord($str{$i}) & 0x40); $i--) { // find the first byte ; } if ($i <= 0) { return ''; } // sanity check for ($bc = 0, $mbs = ord($str{$i}); $mbs & 0x80; $mbs = $mbs << 1) { // calculate number of bytes $bc++; } if ($bc + $i > $len) { return substr($str, 0, $i); } // fallthru: multibyte char fits into length } return substr($str, 0, $len); }
[ "function", "utf8_strtrunc", "(", "$", "str", ",", "$", "len", ")", "{", "$", "i", "=", "$", "len", "-", "1", ";", "if", "(", "ord", "(", "$", "str", "{", "$", "i", "}", ")", "&", "0x80", ")", "{", "// part of a multibyte sequence", "for", "(", ";", "$", "i", ">", "0", "&&", "!", "(", "ord", "(", "$", "str", "{", "$", "i", "}", ")", "&", "0x40", ")", ";", "$", "i", "--", ")", "{", "// find the first byte", ";", "}", "if", "(", "$", "i", "<=", "0", ")", "{", "return", "''", ";", "}", "// sanity check", "for", "(", "$", "bc", "=", "0", ",", "$", "mbs", "=", "ord", "(", "$", "str", "{", "$", "i", "}", ")", ";", "$", "mbs", "&", "0x80", ";", "$", "mbs", "=", "$", "mbs", "<<", "1", ")", "{", "// calculate number of bytes", "$", "bc", "++", ";", "}", "if", "(", "$", "bc", "+", "$", "i", ">", "$", "len", ")", "{", "return", "substr", "(", "$", "str", ",", "0", ",", "$", "i", ")", ";", "}", "// fallthru: multibyte char fits into length", "}", "return", "substr", "(", "$", "str", ",", "0", ",", "$", "len", ")", ";", "}" ]
Truncates a string in UTF-8 short at a given byte length. @param string UTF-8 multibyte character string @param integer the byte length @return string the shortened string @see mb_strcut() @author Martin Kutschker <martin.t.kutschker@blackbox.net>
[ "Truncates", "a", "string", "in", "UTF", "-", "8", "short", "at", "a", "given", "byte", "length", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/typo3/class.t3lib_cs.php#L1934-L1954
212,335
moodle/moodle
lib/typo3/class.t3lib_cs.php
t3lib_cs.utf8_strpos
function utf8_strpos($haystack, $needle, $offset = 0) { if ($GLOBALS['TYPO3_CONF_VARS']['SYS']['t3lib_cs_utils'] == 'mbstring') { return mb_strpos($haystack, $needle, $offset, 'utf-8'); } elseif ($GLOBALS['TYPO3_CONF_VARS']['SYS']['t3lib_cs_utils'] == 'iconv') { return iconv_strpos($haystack, $needle, $offset, 'utf-8'); } $byte_offset = $this->utf8_char2byte_pos($haystack, $offset); if ($byte_offset === FALSE) { return FALSE; } // offset beyond string length $byte_pos = strpos($haystack, $needle, $byte_offset); if ($byte_pos === FALSE) { return FALSE; } // needle not found return $this->utf8_byte2char_pos($haystack, $byte_pos); }
php
function utf8_strpos($haystack, $needle, $offset = 0) { if ($GLOBALS['TYPO3_CONF_VARS']['SYS']['t3lib_cs_utils'] == 'mbstring') { return mb_strpos($haystack, $needle, $offset, 'utf-8'); } elseif ($GLOBALS['TYPO3_CONF_VARS']['SYS']['t3lib_cs_utils'] == 'iconv') { return iconv_strpos($haystack, $needle, $offset, 'utf-8'); } $byte_offset = $this->utf8_char2byte_pos($haystack, $offset); if ($byte_offset === FALSE) { return FALSE; } // offset beyond string length $byte_pos = strpos($haystack, $needle, $byte_offset); if ($byte_pos === FALSE) { return FALSE; } // needle not found return $this->utf8_byte2char_pos($haystack, $byte_pos); }
[ "function", "utf8_strpos", "(", "$", "haystack", ",", "$", "needle", ",", "$", "offset", "=", "0", ")", "{", "if", "(", "$", "GLOBALS", "[", "'TYPO3_CONF_VARS'", "]", "[", "'SYS'", "]", "[", "'t3lib_cs_utils'", "]", "==", "'mbstring'", ")", "{", "return", "mb_strpos", "(", "$", "haystack", ",", "$", "needle", ",", "$", "offset", ",", "'utf-8'", ")", ";", "}", "elseif", "(", "$", "GLOBALS", "[", "'TYPO3_CONF_VARS'", "]", "[", "'SYS'", "]", "[", "'t3lib_cs_utils'", "]", "==", "'iconv'", ")", "{", "return", "iconv_strpos", "(", "$", "haystack", ",", "$", "needle", ",", "$", "offset", ",", "'utf-8'", ")", ";", "}", "$", "byte_offset", "=", "$", "this", "->", "utf8_char2byte_pos", "(", "$", "haystack", ",", "$", "offset", ")", ";", "if", "(", "$", "byte_offset", "===", "FALSE", ")", "{", "return", "FALSE", ";", "}", "// offset beyond string length", "$", "byte_pos", "=", "strpos", "(", "$", "haystack", ",", "$", "needle", ",", "$", "byte_offset", ")", ";", "if", "(", "$", "byte_pos", "===", "FALSE", ")", "{", "return", "FALSE", ";", "}", "// needle not found", "return", "$", "this", "->", "utf8_byte2char_pos", "(", "$", "haystack", ",", "$", "byte_pos", ")", ";", "}" ]
Find position of first occurrence of a string, both arguments are in UTF-8. @param string UTF-8 string to search in @param string UTF-8 string to search for @param integer Positition to start the search @return integer The character position @see strpos() @author Martin Kutschker <martin.t.kutschker@blackbox.net>
[ "Find", "position", "of", "first", "occurrence", "of", "a", "string", "both", "arguments", "are", "in", "UTF", "-", "8", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/typo3/class.t3lib_cs.php#L1966-L1984
212,336
moodle/moodle
lib/typo3/class.t3lib_cs.php
t3lib_cs.utf8_strrpos
function utf8_strrpos($haystack, $needle) { if ($GLOBALS['TYPO3_CONF_VARS']['SYS']['t3lib_cs_utils'] == 'mbstring') { return mb_strrpos($haystack, $needle, 'utf-8'); } elseif ($GLOBALS['TYPO3_CONF_VARS']['SYS']['t3lib_cs_utils'] == 'iconv') { return iconv_strrpos($haystack, $needle, 'utf-8'); } $byte_pos = strrpos($haystack, $needle); if ($byte_pos === FALSE) { return FALSE; } // needle not found return $this->utf8_byte2char_pos($haystack, $byte_pos); }
php
function utf8_strrpos($haystack, $needle) { if ($GLOBALS['TYPO3_CONF_VARS']['SYS']['t3lib_cs_utils'] == 'mbstring') { return mb_strrpos($haystack, $needle, 'utf-8'); } elseif ($GLOBALS['TYPO3_CONF_VARS']['SYS']['t3lib_cs_utils'] == 'iconv') { return iconv_strrpos($haystack, $needle, 'utf-8'); } $byte_pos = strrpos($haystack, $needle); if ($byte_pos === FALSE) { return FALSE; } // needle not found return $this->utf8_byte2char_pos($haystack, $byte_pos); }
[ "function", "utf8_strrpos", "(", "$", "haystack", ",", "$", "needle", ")", "{", "if", "(", "$", "GLOBALS", "[", "'TYPO3_CONF_VARS'", "]", "[", "'SYS'", "]", "[", "'t3lib_cs_utils'", "]", "==", "'mbstring'", ")", "{", "return", "mb_strrpos", "(", "$", "haystack", ",", "$", "needle", ",", "'utf-8'", ")", ";", "}", "elseif", "(", "$", "GLOBALS", "[", "'TYPO3_CONF_VARS'", "]", "[", "'SYS'", "]", "[", "'t3lib_cs_utils'", "]", "==", "'iconv'", ")", "{", "return", "iconv_strrpos", "(", "$", "haystack", ",", "$", "needle", ",", "'utf-8'", ")", ";", "}", "$", "byte_pos", "=", "strrpos", "(", "$", "haystack", ",", "$", "needle", ")", ";", "if", "(", "$", "byte_pos", "===", "FALSE", ")", "{", "return", "FALSE", ";", "}", "// needle not found", "return", "$", "this", "->", "utf8_byte2char_pos", "(", "$", "haystack", ",", "$", "byte_pos", ")", ";", "}" ]
Find position of last occurrence of a char in a string, both arguments are in UTF-8. @param string UTF-8 string to search in @param string UTF-8 character to search for (single character) @return integer The character position @see strrpos() @author Martin Kutschker <martin.t.kutschker@blackbox.net>
[ "Find", "position", "of", "last", "occurrence", "of", "a", "char", "in", "a", "string", "both", "arguments", "are", "in", "UTF", "-", "8", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/typo3/class.t3lib_cs.php#L1995-L2008
212,337
moodle/moodle
lib/typo3/class.t3lib_cs.php
t3lib_cs.utf8_char2byte_pos
function utf8_char2byte_pos($str, $pos) { $n = 0; // number of characters found $p = abs($pos); // number of characters wanted if ($pos >= 0) { $i = 0; $d = 1; } else { $i = strlen($str) - 1; $d = -1; } for (; strlen($str{$i}) && $n < $p; $i += $d) { $c = (int) ord($str{$i}); if (!($c & 0x80)) // single-byte (0xxxxxx) { $n++; } elseif (($c & 0xC0) == 0xC0) // multi-byte starting byte (11xxxxxx) { $n++; } } if (!strlen($str{$i})) { return FALSE; } // offset beyond string length if ($pos >= 0) { // skip trailing multi-byte data bytes while ((ord($str{$i}) & 0x80) && !(ord($str{$i}) & 0x40)) { $i++; } } else { // correct offset $i++; } return $i; }
php
function utf8_char2byte_pos($str, $pos) { $n = 0; // number of characters found $p = abs($pos); // number of characters wanted if ($pos >= 0) { $i = 0; $d = 1; } else { $i = strlen($str) - 1; $d = -1; } for (; strlen($str{$i}) && $n < $p; $i += $d) { $c = (int) ord($str{$i}); if (!($c & 0x80)) // single-byte (0xxxxxx) { $n++; } elseif (($c & 0xC0) == 0xC0) // multi-byte starting byte (11xxxxxx) { $n++; } } if (!strlen($str{$i})) { return FALSE; } // offset beyond string length if ($pos >= 0) { // skip trailing multi-byte data bytes while ((ord($str{$i}) & 0x80) && !(ord($str{$i}) & 0x40)) { $i++; } } else { // correct offset $i++; } return $i; }
[ "function", "utf8_char2byte_pos", "(", "$", "str", ",", "$", "pos", ")", "{", "$", "n", "=", "0", ";", "// number of characters found", "$", "p", "=", "abs", "(", "$", "pos", ")", ";", "// number of characters wanted", "if", "(", "$", "pos", ">=", "0", ")", "{", "$", "i", "=", "0", ";", "$", "d", "=", "1", ";", "}", "else", "{", "$", "i", "=", "strlen", "(", "$", "str", ")", "-", "1", ";", "$", "d", "=", "-", "1", ";", "}", "for", "(", ";", "strlen", "(", "$", "str", "{", "$", "i", "}", ")", "&&", "$", "n", "<", "$", "p", ";", "$", "i", "+=", "$", "d", ")", "{", "$", "c", "=", "(", "int", ")", "ord", "(", "$", "str", "{", "$", "i", "}", ")", ";", "if", "(", "!", "(", "$", "c", "&", "0x80", ")", ")", "// single-byte (0xxxxxx)", "{", "$", "n", "++", ";", "}", "elseif", "(", "(", "$", "c", "&", "0xC0", ")", "==", "0xC0", ")", "// multi-byte starting byte (11xxxxxx)", "{", "$", "n", "++", ";", "}", "}", "if", "(", "!", "strlen", "(", "$", "str", "{", "$", "i", "}", ")", ")", "{", "return", "FALSE", ";", "}", "// offset beyond string length", "if", "(", "$", "pos", ">=", "0", ")", "{", "// skip trailing multi-byte data bytes", "while", "(", "(", "ord", "(", "$", "str", "{", "$", "i", "}", ")", "&", "0x80", ")", "&&", "!", "(", "ord", "(", "$", "str", "{", "$", "i", "}", ")", "&", "0x40", ")", ")", "{", "$", "i", "++", ";", "}", "}", "else", "{", "// correct offset", "$", "i", "++", ";", "}", "return", "$", "i", ";", "}" ]
Translates a character position into an 'absolute' byte position. Unit tested by Kasper. @param string UTF-8 string @param integer Character position (negative values start from the end) @return integer Byte position @author Martin Kutschker <martin.t.kutschker@blackbox.net>
[ "Translates", "a", "character", "position", "into", "an", "absolute", "byte", "position", ".", "Unit", "tested", "by", "Kasper", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/typo3/class.t3lib_cs.php#L2019-L2057
212,338
moodle/moodle
lib/typo3/class.t3lib_cs.php
t3lib_cs.utf8_byte2char_pos
function utf8_byte2char_pos($str, $pos) { $n = 0; // number of characters for ($i = $pos; $i > 0; $i--) { $c = (int) ord($str{$i}); if (!($c & 0x80)) // single-byte (0xxxxxx) { $n++; } elseif (($c & 0xC0) == 0xC0) // multi-byte starting byte (11xxxxxx) { $n++; } } if (!strlen($str{$i})) { return FALSE; } // offset beyond string length return $n; }
php
function utf8_byte2char_pos($str, $pos) { $n = 0; // number of characters for ($i = $pos; $i > 0; $i--) { $c = (int) ord($str{$i}); if (!($c & 0x80)) // single-byte (0xxxxxx) { $n++; } elseif (($c & 0xC0) == 0xC0) // multi-byte starting byte (11xxxxxx) { $n++; } } if (!strlen($str{$i})) { return FALSE; } // offset beyond string length return $n; }
[ "function", "utf8_byte2char_pos", "(", "$", "str", ",", "$", "pos", ")", "{", "$", "n", "=", "0", ";", "// number of characters", "for", "(", "$", "i", "=", "$", "pos", ";", "$", "i", ">", "0", ";", "$", "i", "--", ")", "{", "$", "c", "=", "(", "int", ")", "ord", "(", "$", "str", "{", "$", "i", "}", ")", ";", "if", "(", "!", "(", "$", "c", "&", "0x80", ")", ")", "// single-byte (0xxxxxx)", "{", "$", "n", "++", ";", "}", "elseif", "(", "(", "$", "c", "&", "0xC0", ")", "==", "0xC0", ")", "// multi-byte starting byte (11xxxxxx)", "{", "$", "n", "++", ";", "}", "}", "if", "(", "!", "strlen", "(", "$", "str", "{", "$", "i", "}", ")", ")", "{", "return", "FALSE", ";", "}", "// offset beyond string length", "return", "$", "n", ";", "}" ]
Translates an 'absolute' byte position into a character position. Unit tested by Kasper. @param string UTF-8 string @param integer byte position @return integer character position @author Martin Kutschker <martin.t.kutschker@blackbox.net>
[ "Translates", "an", "absolute", "byte", "position", "into", "a", "character", "position", ".", "Unit", "tested", "by", "Kasper", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/typo3/class.t3lib_cs.php#L2068-L2086
212,339
moodle/moodle
lib/typo3/class.t3lib_cs.php
t3lib_cs.utf8_char_mapping
function utf8_char_mapping($str, $mode, $opt = '') { if (!$this->initUnicodeData($mode)) { return $str; } // do nothing $out = ''; switch ($mode) { case 'case': $map =& $this->caseFolding['utf-8'][$opt]; break; case 'ascii': $map =& $this->toASCII['utf-8']; break; default: return $str; } for ($i = 0; strlen($str{$i}); $i++) { $c = ord($str{$i}); if (!($c & 0x80)) // single-byte (0xxxxxx) { $mbc = $str{$i}; } elseif (($c & 0xC0) == 0xC0) { // multi-byte starting byte (11xxxxxx) for ($bc = 0; $c & 0x80; $c = $c << 1) { $bc++; } // calculate number of bytes $mbc = substr($str, $i, $bc); $i += $bc - 1; } if (isset($map[$mbc])) { $out .= $map[$mbc]; } else { $out .= $mbc; } } return $out; }
php
function utf8_char_mapping($str, $mode, $opt = '') { if (!$this->initUnicodeData($mode)) { return $str; } // do nothing $out = ''; switch ($mode) { case 'case': $map =& $this->caseFolding['utf-8'][$opt]; break; case 'ascii': $map =& $this->toASCII['utf-8']; break; default: return $str; } for ($i = 0; strlen($str{$i}); $i++) { $c = ord($str{$i}); if (!($c & 0x80)) // single-byte (0xxxxxx) { $mbc = $str{$i}; } elseif (($c & 0xC0) == 0xC0) { // multi-byte starting byte (11xxxxxx) for ($bc = 0; $c & 0x80; $c = $c << 1) { $bc++; } // calculate number of bytes $mbc = substr($str, $i, $bc); $i += $bc - 1; } if (isset($map[$mbc])) { $out .= $map[$mbc]; } else { $out .= $mbc; } } return $out; }
[ "function", "utf8_char_mapping", "(", "$", "str", ",", "$", "mode", ",", "$", "opt", "=", "''", ")", "{", "if", "(", "!", "$", "this", "->", "initUnicodeData", "(", "$", "mode", ")", ")", "{", "return", "$", "str", ";", "}", "// do nothing", "$", "out", "=", "''", ";", "switch", "(", "$", "mode", ")", "{", "case", "'case'", ":", "$", "map", "=", "&", "$", "this", "->", "caseFolding", "[", "'utf-8'", "]", "[", "$", "opt", "]", ";", "break", ";", "case", "'ascii'", ":", "$", "map", "=", "&", "$", "this", "->", "toASCII", "[", "'utf-8'", "]", ";", "break", ";", "default", ":", "return", "$", "str", ";", "}", "for", "(", "$", "i", "=", "0", ";", "strlen", "(", "$", "str", "{", "$", "i", "}", ")", ";", "$", "i", "++", ")", "{", "$", "c", "=", "ord", "(", "$", "str", "{", "$", "i", "}", ")", ";", "if", "(", "!", "(", "$", "c", "&", "0x80", ")", ")", "// single-byte (0xxxxxx)", "{", "$", "mbc", "=", "$", "str", "{", "$", "i", "}", ";", "}", "elseif", "(", "(", "$", "c", "&", "0xC0", ")", "==", "0xC0", ")", "{", "// multi-byte starting byte (11xxxxxx)", "for", "(", "$", "bc", "=", "0", ";", "$", "c", "&", "0x80", ";", "$", "c", "=", "$", "c", "<<", "1", ")", "{", "$", "bc", "++", ";", "}", "// calculate number of bytes", "$", "mbc", "=", "substr", "(", "$", "str", ",", "$", "i", ",", "$", "bc", ")", ";", "$", "i", "+=", "$", "bc", "-", "1", ";", "}", "if", "(", "isset", "(", "$", "map", "[", "$", "mbc", "]", ")", ")", "{", "$", "out", ".=", "$", "map", "[", "$", "mbc", "]", ";", "}", "else", "{", "$", "out", ".=", "$", "mbc", ";", "}", "}", "return", "$", "out", ";", "}" ]
Maps all characters of an UTF-8 string. @param string UTF-8 string @param string mode: 'case' (case folding) or 'ascii' (ASCII transliteration) @param string 'case': conversion 'toLower' or 'toUpper' @return string the converted string @author Martin Kutschker <martin.t.kutschker@blackbox.net>
[ "Maps", "all", "characters", "of", "an", "UTF", "-", "8", "string", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/typo3/class.t3lib_cs.php#L2097-L2138
212,340
moodle/moodle
lib/typo3/class.t3lib_cs.php
t3lib_cs.euc_strtrunc
function euc_strtrunc($str, $len, $charset) { $sjis = ($charset == 'shift_jis'); for ($i = 0; strlen($str{$i}) && $i < $len; $i++) { $c = ord($str{$i}); if ($sjis) { if (($c >= 0x80 && $c < 0xA0) || ($c >= 0xE0)) { $i++; } // advance a double-byte char } else { if ($c >= 0x80) { $i++; } // advance a double-byte char } } if (!strlen($str{$i})) { return $str; } // string shorter than supplied length if ($i > $len) { return substr($str, 0, $len - 1); // we ended on a first byte } else { return substr($str, 0, $len); } }
php
function euc_strtrunc($str, $len, $charset) { $sjis = ($charset == 'shift_jis'); for ($i = 0; strlen($str{$i}) && $i < $len; $i++) { $c = ord($str{$i}); if ($sjis) { if (($c >= 0x80 && $c < 0xA0) || ($c >= 0xE0)) { $i++; } // advance a double-byte char } else { if ($c >= 0x80) { $i++; } // advance a double-byte char } } if (!strlen($str{$i})) { return $str; } // string shorter than supplied length if ($i > $len) { return substr($str, 0, $len - 1); // we ended on a first byte } else { return substr($str, 0, $len); } }
[ "function", "euc_strtrunc", "(", "$", "str", ",", "$", "len", ",", "$", "charset", ")", "{", "$", "sjis", "=", "(", "$", "charset", "==", "'shift_jis'", ")", ";", "for", "(", "$", "i", "=", "0", ";", "strlen", "(", "$", "str", "{", "$", "i", "}", ")", "&&", "$", "i", "<", "$", "len", ";", "$", "i", "++", ")", "{", "$", "c", "=", "ord", "(", "$", "str", "{", "$", "i", "}", ")", ";", "if", "(", "$", "sjis", ")", "{", "if", "(", "(", "$", "c", ">=", "0x80", "&&", "$", "c", "<", "0xA0", ")", "||", "(", "$", "c", ">=", "0xE0", ")", ")", "{", "$", "i", "++", ";", "}", "// advance a double-byte char", "}", "else", "{", "if", "(", "$", "c", ">=", "0x80", ")", "{", "$", "i", "++", ";", "}", "// advance a double-byte char", "}", "}", "if", "(", "!", "strlen", "(", "$", "str", "{", "$", "i", "}", ")", ")", "{", "return", "$", "str", ";", "}", "// string shorter than supplied length", "if", "(", "$", "i", ">", "$", "len", ")", "{", "return", "substr", "(", "$", "str", ",", "0", ",", "$", "len", "-", "1", ")", ";", "// we ended on a first byte", "}", "else", "{", "return", "substr", "(", "$", "str", ",", "0", ",", "$", "len", ")", ";", "}", "}" ]
Cuts a string in the EUC charset family short at a given byte length. @param string EUC multibyte character string @param integer the byte length @param string the charset @return string the shortened string @see mb_strcut() @author Martin Kutschker <martin.t.kutschker@blackbox.net>
[ "Cuts", "a", "string", "in", "the", "EUC", "charset", "family", "short", "at", "a", "given", "byte", "length", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/typo3/class.t3lib_cs.php#L2163-L2187
212,341
moodle/moodle
lib/typo3/class.t3lib_cs.php
t3lib_cs.euc_substr
function euc_substr($str, $start, $charset, $len = NULL) { $byte_start = $this->euc_char2byte_pos($str, $start, $charset); if ($byte_start === FALSE) { return FALSE; } // $start outside string length $str = substr($str, $byte_start); if ($len != NULL) { $byte_end = $this->euc_char2byte_pos($str, $len, $charset); if ($byte_end === FALSE) // $len outside actual string length { return $str; } else { return substr($str, 0, $byte_end); } } else { return $str; } }
php
function euc_substr($str, $start, $charset, $len = NULL) { $byte_start = $this->euc_char2byte_pos($str, $start, $charset); if ($byte_start === FALSE) { return FALSE; } // $start outside string length $str = substr($str, $byte_start); if ($len != NULL) { $byte_end = $this->euc_char2byte_pos($str, $len, $charset); if ($byte_end === FALSE) // $len outside actual string length { return $str; } else { return substr($str, 0, $byte_end); } } else { return $str; } }
[ "function", "euc_substr", "(", "$", "str", ",", "$", "start", ",", "$", "charset", ",", "$", "len", "=", "NULL", ")", "{", "$", "byte_start", "=", "$", "this", "->", "euc_char2byte_pos", "(", "$", "str", ",", "$", "start", ",", "$", "charset", ")", ";", "if", "(", "$", "byte_start", "===", "FALSE", ")", "{", "return", "FALSE", ";", "}", "// $start outside string length", "$", "str", "=", "substr", "(", "$", "str", ",", "$", "byte_start", ")", ";", "if", "(", "$", "len", "!=", "NULL", ")", "{", "$", "byte_end", "=", "$", "this", "->", "euc_char2byte_pos", "(", "$", "str", ",", "$", "len", ",", "$", "charset", ")", ";", "if", "(", "$", "byte_end", "===", "FALSE", ")", "// $len outside actual string length", "{", "return", "$", "str", ";", "}", "else", "{", "return", "substr", "(", "$", "str", ",", "0", ",", "$", "byte_end", ")", ";", "}", "}", "else", "{", "return", "$", "str", ";", "}", "}" ]
Returns a part of a string in the EUC charset family. @param string EUC multibyte character string @param integer start position (character position) @param string the charset @param integer length (in characters) @return string the substring @author Martin Kutschker <martin.t.kutschker@blackbox.net>
[ "Returns", "a", "part", "of", "a", "string", "in", "the", "EUC", "charset", "family", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/typo3/class.t3lib_cs.php#L2199-L2221
212,342
moodle/moodle
lib/typo3/class.t3lib_cs.php
t3lib_cs.euc_strlen
function euc_strlen($str, $charset) { $sjis = ($charset == 'shift_jis'); $n = 0; for ($i = 0; strlen($str{$i}); $i++) { $c = ord($str{$i}); if ($sjis) { if (($c >= 0x80 && $c < 0xA0) || ($c >= 0xE0)) { $i++; } // advance a double-byte char } else { if ($c >= 0x80) { $i++; } // advance a double-byte char } $n++; } return $n; }
php
function euc_strlen($str, $charset) { $sjis = ($charset == 'shift_jis'); $n = 0; for ($i = 0; strlen($str{$i}); $i++) { $c = ord($str{$i}); if ($sjis) { if (($c >= 0x80 && $c < 0xA0) || ($c >= 0xE0)) { $i++; } // advance a double-byte char } else { if ($c >= 0x80) { $i++; } // advance a double-byte char } $n++; } return $n; }
[ "function", "euc_strlen", "(", "$", "str", ",", "$", "charset", ")", "{", "$", "sjis", "=", "(", "$", "charset", "==", "'shift_jis'", ")", ";", "$", "n", "=", "0", ";", "for", "(", "$", "i", "=", "0", ";", "strlen", "(", "$", "str", "{", "$", "i", "}", ")", ";", "$", "i", "++", ")", "{", "$", "c", "=", "ord", "(", "$", "str", "{", "$", "i", "}", ")", ";", "if", "(", "$", "sjis", ")", "{", "if", "(", "(", "$", "c", ">=", "0x80", "&&", "$", "c", "<", "0xA0", ")", "||", "(", "$", "c", ">=", "0xE0", ")", ")", "{", "$", "i", "++", ";", "}", "// advance a double-byte char", "}", "else", "{", "if", "(", "$", "c", ">=", "0x80", ")", "{", "$", "i", "++", ";", "}", "// advance a double-byte char", "}", "$", "n", "++", ";", "}", "return", "$", "n", ";", "}" ]
Counts the number of characters of a string in the EUC charset family. @param string EUC multibyte character string @param string the charset @return integer the number of characters @see strlen() @author Martin Kutschker <martin.t.kutschker@blackbox.net>
[ "Counts", "the", "number", "of", "characters", "of", "a", "string", "in", "the", "EUC", "charset", "family", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/typo3/class.t3lib_cs.php#L2232-L2252
212,343
moodle/moodle
lib/typo3/class.t3lib_cs.php
t3lib_cs.euc_char2byte_pos
function euc_char2byte_pos($str, $pos, $charset) { $sjis = ($charset == 'shift_jis'); $n = 0; // number of characters seen $p = abs($pos); // number of characters wanted if ($pos >= 0) { $i = 0; $d = 1; } else { $i = strlen($str) - 1; $d = -1; } for (; strlen($str{$i}) && $n < $p; $i += $d) { $c = ord($str{$i}); if ($sjis) { if (($c >= 0x80 && $c < 0xA0) || ($c >= 0xE0)) { $i += $d; } // advance a double-byte char } else { if ($c >= 0x80) { $i += $d; } // advance a double-byte char } $n++; } if (!strlen($str{$i})) { return FALSE; } // offset beyond string length if ($pos < 0) { $i++; } // correct offset return $i; }
php
function euc_char2byte_pos($str, $pos, $charset) { $sjis = ($charset == 'shift_jis'); $n = 0; // number of characters seen $p = abs($pos); // number of characters wanted if ($pos >= 0) { $i = 0; $d = 1; } else { $i = strlen($str) - 1; $d = -1; } for (; strlen($str{$i}) && $n < $p; $i += $d) { $c = ord($str{$i}); if ($sjis) { if (($c >= 0x80 && $c < 0xA0) || ($c >= 0xE0)) { $i += $d; } // advance a double-byte char } else { if ($c >= 0x80) { $i += $d; } // advance a double-byte char } $n++; } if (!strlen($str{$i})) { return FALSE; } // offset beyond string length if ($pos < 0) { $i++; } // correct offset return $i; }
[ "function", "euc_char2byte_pos", "(", "$", "str", ",", "$", "pos", ",", "$", "charset", ")", "{", "$", "sjis", "=", "(", "$", "charset", "==", "'shift_jis'", ")", ";", "$", "n", "=", "0", ";", "// number of characters seen", "$", "p", "=", "abs", "(", "$", "pos", ")", ";", "// number of characters wanted", "if", "(", "$", "pos", ">=", "0", ")", "{", "$", "i", "=", "0", ";", "$", "d", "=", "1", ";", "}", "else", "{", "$", "i", "=", "strlen", "(", "$", "str", ")", "-", "1", ";", "$", "d", "=", "-", "1", ";", "}", "for", "(", ";", "strlen", "(", "$", "str", "{", "$", "i", "}", ")", "&&", "$", "n", "<", "$", "p", ";", "$", "i", "+=", "$", "d", ")", "{", "$", "c", "=", "ord", "(", "$", "str", "{", "$", "i", "}", ")", ";", "if", "(", "$", "sjis", ")", "{", "if", "(", "(", "$", "c", ">=", "0x80", "&&", "$", "c", "<", "0xA0", ")", "||", "(", "$", "c", ">=", "0xE0", ")", ")", "{", "$", "i", "+=", "$", "d", ";", "}", "// advance a double-byte char", "}", "else", "{", "if", "(", "$", "c", ">=", "0x80", ")", "{", "$", "i", "+=", "$", "d", ";", "}", "// advance a double-byte char", "}", "$", "n", "++", ";", "}", "if", "(", "!", "strlen", "(", "$", "str", "{", "$", "i", "}", ")", ")", "{", "return", "FALSE", ";", "}", "// offset beyond string length", "if", "(", "$", "pos", "<", "0", ")", "{", "$", "i", "++", ";", "}", "// correct offset", "return", "$", "i", ";", "}" ]
Translates a character position into an 'absolute' byte position. @param string EUC multibyte character string @param integer character position (negative values start from the end) @param string the charset @return integer byte position @author Martin Kutschker <martin.t.kutschker@blackbox.net>
[ "Translates", "a", "character", "position", "into", "an", "absolute", "byte", "position", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/typo3/class.t3lib_cs.php#L2263-L2300
212,344
moodle/moodle
lib/typo3/class.t3lib_cs.php
t3lib_cs.euc_char_mapping
function euc_char_mapping($str, $charset, $mode, $opt = '') { switch ($mode) { case 'case': if (!$this->initCaseFolding($charset)) { return $str; } // do nothing $map =& $this->caseFolding[$charset][$opt]; break; case 'ascii': if (!$this->initToASCII($charset)) { return $str; } // do nothing $map =& $this->toASCII[$charset]; break; default: return $str; } $sjis = ($charset == 'shift_jis'); $out = ''; for ($i = 0; strlen($str{$i}); $i++) { $mbc = $str{$i}; $c = ord($mbc); if ($sjis) { if (($c >= 0x80 && $c < 0xA0) || ($c >= 0xE0)) { // a double-byte char $mbc = substr($str, $i, 2); $i++; } } else { if ($c >= 0x80) { // a double-byte char $mbc = substr($str, $i, 2); $i++; } } if (isset($map[$mbc])) { $out .= $map[$mbc]; } else { $out .= $mbc; } } return $out; }
php
function euc_char_mapping($str, $charset, $mode, $opt = '') { switch ($mode) { case 'case': if (!$this->initCaseFolding($charset)) { return $str; } // do nothing $map =& $this->caseFolding[$charset][$opt]; break; case 'ascii': if (!$this->initToASCII($charset)) { return $str; } // do nothing $map =& $this->toASCII[$charset]; break; default: return $str; } $sjis = ($charset == 'shift_jis'); $out = ''; for ($i = 0; strlen($str{$i}); $i++) { $mbc = $str{$i}; $c = ord($mbc); if ($sjis) { if (($c >= 0x80 && $c < 0xA0) || ($c >= 0xE0)) { // a double-byte char $mbc = substr($str, $i, 2); $i++; } } else { if ($c >= 0x80) { // a double-byte char $mbc = substr($str, $i, 2); $i++; } } if (isset($map[$mbc])) { $out .= $map[$mbc]; } else { $out .= $mbc; } } return $out; }
[ "function", "euc_char_mapping", "(", "$", "str", ",", "$", "charset", ",", "$", "mode", ",", "$", "opt", "=", "''", ")", "{", "switch", "(", "$", "mode", ")", "{", "case", "'case'", ":", "if", "(", "!", "$", "this", "->", "initCaseFolding", "(", "$", "charset", ")", ")", "{", "return", "$", "str", ";", "}", "// do nothing", "$", "map", "=", "&", "$", "this", "->", "caseFolding", "[", "$", "charset", "]", "[", "$", "opt", "]", ";", "break", ";", "case", "'ascii'", ":", "if", "(", "!", "$", "this", "->", "initToASCII", "(", "$", "charset", ")", ")", "{", "return", "$", "str", ";", "}", "// do nothing", "$", "map", "=", "&", "$", "this", "->", "toASCII", "[", "$", "charset", "]", ";", "break", ";", "default", ":", "return", "$", "str", ";", "}", "$", "sjis", "=", "(", "$", "charset", "==", "'shift_jis'", ")", ";", "$", "out", "=", "''", ";", "for", "(", "$", "i", "=", "0", ";", "strlen", "(", "$", "str", "{", "$", "i", "}", ")", ";", "$", "i", "++", ")", "{", "$", "mbc", "=", "$", "str", "{", "$", "i", "}", ";", "$", "c", "=", "ord", "(", "$", "mbc", ")", ";", "if", "(", "$", "sjis", ")", "{", "if", "(", "(", "$", "c", ">=", "0x80", "&&", "$", "c", "<", "0xA0", ")", "||", "(", "$", "c", ">=", "0xE0", ")", ")", "{", "// a double-byte char", "$", "mbc", "=", "substr", "(", "$", "str", ",", "$", "i", ",", "2", ")", ";", "$", "i", "++", ";", "}", "}", "else", "{", "if", "(", "$", "c", ">=", "0x80", ")", "{", "// a double-byte char", "$", "mbc", "=", "substr", "(", "$", "str", ",", "$", "i", ",", "2", ")", ";", "$", "i", "++", ";", "}", "}", "if", "(", "isset", "(", "$", "map", "[", "$", "mbc", "]", ")", ")", "{", "$", "out", ".=", "$", "map", "[", "$", "mbc", "]", ";", "}", "else", "{", "$", "out", ".=", "$", "mbc", ";", "}", "}", "return", "$", "out", ";", "}" ]
Maps all characters of a string in the EUC charset family. @param string EUC multibyte character string @param string the charset @param string mode: 'case' (case folding) or 'ascii' (ASCII transliteration) @param string 'case': conversion 'toLower' or 'toUpper' @return string the converted string @author Martin Kutschker <martin.t.kutschker@blackbox.net>
[ "Maps", "all", "characters", "of", "a", "string", "in", "the", "EUC", "charset", "family", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/typo3/class.t3lib_cs.php#L2312-L2359
212,345
moodle/moodle
lib/spout/src/Spout/Writer/Style/Style.php
Style.setFontColor
public function setFontColor($fontColor) { $this->fontColor = $fontColor; $this->hasSetFontColor = true; $this->shouldApplyFont = true; return $this; }
php
public function setFontColor($fontColor) { $this->fontColor = $fontColor; $this->hasSetFontColor = true; $this->shouldApplyFont = true; return $this; }
[ "public", "function", "setFontColor", "(", "$", "fontColor", ")", "{", "$", "this", "->", "fontColor", "=", "$", "fontColor", ";", "$", "this", "->", "hasSetFontColor", "=", "true", ";", "$", "this", "->", "shouldApplyFont", "=", "true", ";", "return", "$", "this", ";", "}" ]
Sets the font color. @param string $fontColor ARGB color (@see Color) @return Style
[ "Sets", "the", "font", "color", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/spout/src/Spout/Writer/Style/Style.php#L236-L242
212,346
moodle/moodle
lib/spout/src/Spout/Writer/Style/Style.php
Style.serialize
public function serialize() { // In order to be able to properly compare style, set static ID value $currentId = $this->id; $this->setId(0); $serializedStyle = serialize($this); $this->setId($currentId); return $serializedStyle; }
php
public function serialize() { // In order to be able to properly compare style, set static ID value $currentId = $this->id; $this->setId(0); $serializedStyle = serialize($this); $this->setId($currentId); return $serializedStyle; }
[ "public", "function", "serialize", "(", ")", "{", "// In order to be able to properly compare style, set static ID value", "$", "currentId", "=", "$", "this", "->", "id", ";", "$", "this", "->", "setId", "(", "0", ")", ";", "$", "serializedStyle", "=", "serialize", "(", "$", "this", ")", ";", "$", "this", "->", "setId", "(", "$", "currentId", ")", ";", "return", "$", "serializedStyle", ";", "}" ]
Serializes the style for future comparison with other styles. The ID is excluded from the comparison, as we only care about actual style properties. @return string The serialized style
[ "Serializes", "the", "style", "for", "future", "comparison", "with", "other", "styles", ".", "The", "ID", "is", "excluded", "from", "the", "comparison", "as", "we", "only", "care", "about", "actual", "style", "properties", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/spout/src/Spout/Writer/Style/Style.php#L335-L346
212,347
moodle/moodle
mod/forum/classes/local/vaults/forum.php
forum.from_db_records
protected function from_db_records(array $results) : array { $entityfactory = $this->get_entity_factory(); return array_map(function(array $result) use ($entityfactory) { [ 'forum' => $forumrecord, 'course_module' => $coursemodule, 'course' => $course, 'context' => $context, ] = $result; return $entityfactory->get_forum_from_stdclass($forumrecord, $context, $coursemodule, $course); }, $results); }
php
protected function from_db_records(array $results) : array { $entityfactory = $this->get_entity_factory(); return array_map(function(array $result) use ($entityfactory) { [ 'forum' => $forumrecord, 'course_module' => $coursemodule, 'course' => $course, 'context' => $context, ] = $result; return $entityfactory->get_forum_from_stdclass($forumrecord, $context, $coursemodule, $course); }, $results); }
[ "protected", "function", "from_db_records", "(", "array", "$", "results", ")", ":", "array", "{", "$", "entityfactory", "=", "$", "this", "->", "get_entity_factory", "(", ")", ";", "return", "array_map", "(", "function", "(", "array", "$", "result", ")", "use", "(", "$", "entityfactory", ")", "{", "[", "'forum'", "=>", "$", "forumrecord", ",", "'course_module'", "=>", "$", "coursemodule", ",", "'course'", "=>", "$", "course", ",", "'context'", "=>", "$", "context", ",", "]", "=", "$", "result", ";", "return", "$", "entityfactory", "->", "get_forum_from_stdclass", "(", "$", "forumrecord", ",", "$", "context", ",", "$", "coursemodule", ",", "$", "course", ")", ";", "}", ",", "$", "results", ")", ";", "}" ]
Convert the DB records into forum entities. @param array $results The DB records @return forum_entity[]
[ "Convert", "the", "DB", "records", "into", "forum", "entities", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/forum/classes/local/vaults/forum.php#L119-L131
212,348
moodle/moodle
mod/forum/classes/local/vaults/forum.php
forum.get_from_course_module_id
public function get_from_course_module_id(int $id) : ?forum_entity { $records = $this->get_from_course_module_ids([$id]); return count($records) ? array_shift($records) : null; }
php
public function get_from_course_module_id(int $id) : ?forum_entity { $records = $this->get_from_course_module_ids([$id]); return count($records) ? array_shift($records) : null; }
[ "public", "function", "get_from_course_module_id", "(", "int", "$", "id", ")", ":", "?", "forum_entity", "{", "$", "records", "=", "$", "this", "->", "get_from_course_module_ids", "(", "[", "$", "id", "]", ")", ";", "return", "count", "(", "$", "records", ")", "?", "array_shift", "(", "$", "records", ")", ":", "null", ";", "}" ]
Get the forum for the given course module id. @param int $id The course module id @return forum_entity|null
[ "Get", "the", "forum", "for", "the", "given", "course", "module", "id", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/forum/classes/local/vaults/forum.php#L139-L142
212,349
moodle/moodle
mod/forum/classes/local/vaults/forum.php
forum.get_from_post_id
public function get_from_post_id(int $id) : ?forum_entity { $alias = $this->get_table_alias(); $thistable = new dml_table(self::TABLE, $alias, $alias); $coursemoduletable = new dml_table('course_modules', 'cm', 'cm_'); $coursetable = new dml_table('course', 'c', 'c_'); $tablefields = $thistable->get_field_select(); $coursemodulefields = $coursemoduletable->get_field_select(); $coursefields = $coursetable->get_field_select(); $fields = implode(', ', [ $tablefields, context_helper::get_preload_record_columns_sql('ctx'), $coursemodulefields, $coursefields, ]); $tables = "{forum_posts} p"; $tables .= " JOIN {forum_discussions} d ON d.id = p.discussion"; $tables .= ' JOIN {' . self::TABLE . "} {$alias} ON {$alias}.id = d.forum"; $tables .= " JOIN {modules} m ON m.name = 'forum'"; $tables .= " JOIN {course_modules} cm ON cm.module = m.id AND cm.instance = {$alias}.id"; $tables .= ' JOIN {context} ctx ON ctx.contextlevel = ' . CONTEXT_MODULE . ' AND ctx.instanceid = cm.id'; $tables .= " JOIN {course} c ON c.id = {$alias}.course"; $sql = "SELECT {$fields} FROM {$tables} WHERE p.id = :postid"; $records = $this->get_db()->get_records_sql($sql, [ 'postid' => $id, ]); $records = $this->transform_db_records_to_entities($records); return count($records) ? array_shift($records) : null; }
php
public function get_from_post_id(int $id) : ?forum_entity { $alias = $this->get_table_alias(); $thistable = new dml_table(self::TABLE, $alias, $alias); $coursemoduletable = new dml_table('course_modules', 'cm', 'cm_'); $coursetable = new dml_table('course', 'c', 'c_'); $tablefields = $thistable->get_field_select(); $coursemodulefields = $coursemoduletable->get_field_select(); $coursefields = $coursetable->get_field_select(); $fields = implode(', ', [ $tablefields, context_helper::get_preload_record_columns_sql('ctx'), $coursemodulefields, $coursefields, ]); $tables = "{forum_posts} p"; $tables .= " JOIN {forum_discussions} d ON d.id = p.discussion"; $tables .= ' JOIN {' . self::TABLE . "} {$alias} ON {$alias}.id = d.forum"; $tables .= " JOIN {modules} m ON m.name = 'forum'"; $tables .= " JOIN {course_modules} cm ON cm.module = m.id AND cm.instance = {$alias}.id"; $tables .= ' JOIN {context} ctx ON ctx.contextlevel = ' . CONTEXT_MODULE . ' AND ctx.instanceid = cm.id'; $tables .= " JOIN {course} c ON c.id = {$alias}.course"; $sql = "SELECT {$fields} FROM {$tables} WHERE p.id = :postid"; $records = $this->get_db()->get_records_sql($sql, [ 'postid' => $id, ]); $records = $this->transform_db_records_to_entities($records); return count($records) ? array_shift($records) : null; }
[ "public", "function", "get_from_post_id", "(", "int", "$", "id", ")", ":", "?", "forum_entity", "{", "$", "alias", "=", "$", "this", "->", "get_table_alias", "(", ")", ";", "$", "thistable", "=", "new", "dml_table", "(", "self", "::", "TABLE", ",", "$", "alias", ",", "$", "alias", ")", ";", "$", "coursemoduletable", "=", "new", "dml_table", "(", "'course_modules'", ",", "'cm'", ",", "'cm_'", ")", ";", "$", "coursetable", "=", "new", "dml_table", "(", "'course'", ",", "'c'", ",", "'c_'", ")", ";", "$", "tablefields", "=", "$", "thistable", "->", "get_field_select", "(", ")", ";", "$", "coursemodulefields", "=", "$", "coursemoduletable", "->", "get_field_select", "(", ")", ";", "$", "coursefields", "=", "$", "coursetable", "->", "get_field_select", "(", ")", ";", "$", "fields", "=", "implode", "(", "', '", ",", "[", "$", "tablefields", ",", "context_helper", "::", "get_preload_record_columns_sql", "(", "'ctx'", ")", ",", "$", "coursemodulefields", ",", "$", "coursefields", ",", "]", ")", ";", "$", "tables", "=", "\"{forum_posts} p\"", ";", "$", "tables", ".=", "\" JOIN {forum_discussions} d ON d.id = p.discussion\"", ";", "$", "tables", ".=", "' JOIN {'", ".", "self", "::", "TABLE", ".", "\"} {$alias} ON {$alias}.id = d.forum\"", ";", "$", "tables", ".=", "\" JOIN {modules} m ON m.name = 'forum'\"", ";", "$", "tables", ".=", "\" JOIN {course_modules} cm ON cm.module = m.id AND cm.instance = {$alias}.id\"", ";", "$", "tables", ".=", "' JOIN {context} ctx ON ctx.contextlevel = '", ".", "CONTEXT_MODULE", ".", "' AND ctx.instanceid = cm.id'", ";", "$", "tables", ".=", "\" JOIN {course} c ON c.id = {$alias}.course\"", ";", "$", "sql", "=", "\"SELECT {$fields} FROM {$tables} WHERE p.id = :postid\"", ";", "$", "records", "=", "$", "this", "->", "get_db", "(", ")", "->", "get_records_sql", "(", "$", "sql", ",", "[", "'postid'", "=>", "$", "id", ",", "]", ")", ";", "$", "records", "=", "$", "this", "->", "transform_db_records_to_entities", "(", "$", "records", ")", ";", "return", "count", "(", "$", "records", ")", "?", "array_shift", "(", "$", "records", ")", ":", "null", ";", "}" ]
Get the forum entity for the given post id. @param int $id The course module id @return forum_entity|null
[ "Get", "the", "forum", "entity", "for", "the", "given", "post", "id", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/forum/classes/local/vaults/forum.php#L166-L198
212,350
moodle/moodle
lib/phpexcel/PHPExcel/Shared/JAMA/SingularValueDecomposition.php
SingularValueDecomposition.getU
public function getU() { return new Matrix($this->U, $this->m, min($this->m + 1, $this->n)); }
php
public function getU() { return new Matrix($this->U, $this->m, min($this->m + 1, $this->n)); }
[ "public", "function", "getU", "(", ")", "{", "return", "new", "Matrix", "(", "$", "this", "->", "U", ",", "$", "this", "->", "m", ",", "min", "(", "$", "this", "->", "m", "+", "1", ",", "$", "this", "->", "n", ")", ")", ";", "}" ]
Return the left singular vectors @access public @return U
[ "Return", "the", "left", "singular", "vectors" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/phpexcel/PHPExcel/Shared/JAMA/SingularValueDecomposition.php#L438-L441
212,351
moodle/moodle
lib/phpexcel/PHPExcel/Shared/JAMA/SingularValueDecomposition.php
SingularValueDecomposition.getS
public function getS() { for ($i = 0; $i < $this->n; ++$i) { for ($j = 0; $j < $this->n; ++$j) { $S[$i][$j] = 0.0; } $S[$i][$i] = $this->s[$i]; } return new Matrix($S); }
php
public function getS() { for ($i = 0; $i < $this->n; ++$i) { for ($j = 0; $j < $this->n; ++$j) { $S[$i][$j] = 0.0; } $S[$i][$i] = $this->s[$i]; } return new Matrix($S); }
[ "public", "function", "getS", "(", ")", "{", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "$", "this", "->", "n", ";", "++", "$", "i", ")", "{", "for", "(", "$", "j", "=", "0", ";", "$", "j", "<", "$", "this", "->", "n", ";", "++", "$", "j", ")", "{", "$", "S", "[", "$", "i", "]", "[", "$", "j", "]", "=", "0.0", ";", "}", "$", "S", "[", "$", "i", "]", "[", "$", "i", "]", "=", "$", "this", "->", "s", "[", "$", "i", "]", ";", "}", "return", "new", "Matrix", "(", "$", "S", ")", ";", "}" ]
Return the diagonal matrix of singular values @access public @return S
[ "Return", "the", "diagonal", "matrix", "of", "singular", "values" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/phpexcel/PHPExcel/Shared/JAMA/SingularValueDecomposition.php#L474-L483
212,352
moodle/moodle
lib/phpexcel/PHPExcel/Shared/JAMA/SingularValueDecomposition.php
SingularValueDecomposition.cond
public function cond() { return $this->s[0] / $this->s[min($this->m, $this->n) - 1]; }
php
public function cond() { return $this->s[0] / $this->s[min($this->m, $this->n) - 1]; }
[ "public", "function", "cond", "(", ")", "{", "return", "$", "this", "->", "s", "[", "0", "]", "/", "$", "this", "->", "s", "[", "min", "(", "$", "this", "->", "m", ",", "$", "this", "->", "n", ")", "-", "1", "]", ";", "}" ]
Two norm condition number @access public @return max(S)/min(S)
[ "Two", "norm", "condition", "number" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/phpexcel/PHPExcel/Shared/JAMA/SingularValueDecomposition.php#L504-L507
212,353
moodle/moodle
lib/phpexcel/PHPExcel/Shared/JAMA/SingularValueDecomposition.php
SingularValueDecomposition.rank
public function rank() { $eps = pow(2.0, -52.0); $tol = max($this->m, $this->n) * $this->s[0] * $eps; $r = 0; for ($i = 0; $i < count($this->s); ++$i) { if ($this->s[$i] > $tol) { ++$r; } } return $r; }
php
public function rank() { $eps = pow(2.0, -52.0); $tol = max($this->m, $this->n) * $this->s[0] * $eps; $r = 0; for ($i = 0; $i < count($this->s); ++$i) { if ($this->s[$i] > $tol) { ++$r; } } return $r; }
[ "public", "function", "rank", "(", ")", "{", "$", "eps", "=", "pow", "(", "2.0", ",", "-", "52.0", ")", ";", "$", "tol", "=", "max", "(", "$", "this", "->", "m", ",", "$", "this", "->", "n", ")", "*", "$", "this", "->", "s", "[", "0", "]", "*", "$", "eps", ";", "$", "r", "=", "0", ";", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "count", "(", "$", "this", "->", "s", ")", ";", "++", "$", "i", ")", "{", "if", "(", "$", "this", "->", "s", "[", "$", "i", "]", ">", "$", "tol", ")", "{", "++", "$", "r", ";", "}", "}", "return", "$", "r", ";", "}" ]
Effective numerical matrix rank @access public @return Number of nonnegligible singular values.
[ "Effective", "numerical", "matrix", "rank" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/phpexcel/PHPExcel/Shared/JAMA/SingularValueDecomposition.php#L516-L527
212,354
moodle/moodle
lib/outputactions.php
popup_action.get_js_options
public function get_js_options() { $jsoptions = ''; foreach ($this->params as $var => $val) { if (is_string($val) || is_int($val)) { $jsoptions .= "$var=$val,"; } elseif (is_bool($val)) { $jsoptions .= ($val) ? "$var," : "$var=0,"; } } $jsoptions = substr($jsoptions, 0, strlen($jsoptions) - 1); return $jsoptions; }
php
public function get_js_options() { $jsoptions = ''; foreach ($this->params as $var => $val) { if (is_string($val) || is_int($val)) { $jsoptions .= "$var=$val,"; } elseif (is_bool($val)) { $jsoptions .= ($val) ? "$var," : "$var=0,"; } } $jsoptions = substr($jsoptions, 0, strlen($jsoptions) - 1); return $jsoptions; }
[ "public", "function", "get_js_options", "(", ")", "{", "$", "jsoptions", "=", "''", ";", "foreach", "(", "$", "this", "->", "params", "as", "$", "var", "=>", "$", "val", ")", "{", "if", "(", "is_string", "(", "$", "val", ")", "||", "is_int", "(", "$", "val", ")", ")", "{", "$", "jsoptions", ".=", "\"$var=$val,\"", ";", "}", "elseif", "(", "is_bool", "(", "$", "val", ")", ")", "{", "$", "jsoptions", ".=", "(", "$", "val", ")", "?", "\"$var,\"", ":", "\"$var=0,\"", ";", "}", "}", "$", "jsoptions", "=", "substr", "(", "$", "jsoptions", ",", "0", ",", "strlen", "(", "$", "jsoptions", ")", "-", "1", ")", ";", "return", "$", "jsoptions", ";", "}" ]
Returns a string of concatenated option->value pairs used by JS to call the popup window, based on this object's variables @return string String of option->value pairs for JS popup function.
[ "Returns", "a", "string", "of", "concatenated", "option", "-", ">", "value", "pairs", "used", "by", "JS", "to", "call", "the", "popup", "window", "based", "on", "this", "object", "s", "variables" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/outputactions.php#L206-L220
212,355
moodle/moodle
cache/stores/mongodb/MongoDB/Operation/DropIndexes.php
DropIndexes.createCommand
private function createCommand() { $cmd = [ 'dropIndexes' => $this->collectionName, 'index' => $this->indexName, ]; if (isset($this->options['maxTimeMS'])) { $cmd['maxTimeMS'] = $this->options['maxTimeMS']; } return new Command($cmd); }
php
private function createCommand() { $cmd = [ 'dropIndexes' => $this->collectionName, 'index' => $this->indexName, ]; if (isset($this->options['maxTimeMS'])) { $cmd['maxTimeMS'] = $this->options['maxTimeMS']; } return new Command($cmd); }
[ "private", "function", "createCommand", "(", ")", "{", "$", "cmd", "=", "[", "'dropIndexes'", "=>", "$", "this", "->", "collectionName", ",", "'index'", "=>", "$", "this", "->", "indexName", ",", "]", ";", "if", "(", "isset", "(", "$", "this", "->", "options", "[", "'maxTimeMS'", "]", ")", ")", "{", "$", "cmd", "[", "'maxTimeMS'", "]", "=", "$", "this", "->", "options", "[", "'maxTimeMS'", "]", ";", "}", "return", "new", "Command", "(", "$", "cmd", ")", ";", "}" ]
Create the dropIndexes command. @return Command
[ "Create", "the", "dropIndexes", "command", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cache/stores/mongodb/MongoDB/Operation/DropIndexes.php#L133-L145
212,356
moodle/moodle
privacy/classes/local/metadata/collection.php
collection.add_database_table
public function add_database_table($name, array $privacyfields, $summary = '') { $this->add_type(new types\database_table($name, $privacyfields, $summary)); return $this; }
php
public function add_database_table($name, array $privacyfields, $summary = '') { $this->add_type(new types\database_table($name, $privacyfields, $summary)); return $this; }
[ "public", "function", "add_database_table", "(", "$", "name", ",", "array", "$", "privacyfields", ",", "$", "summary", "=", "''", ")", "{", "$", "this", "->", "add_type", "(", "new", "types", "\\", "database_table", "(", "$", "name", ",", "$", "privacyfields", ",", "$", "summary", ")", ")", ";", "return", "$", "this", ";", "}" ]
Function to add a database table which contains user data to this collection. @param string $name the name of the database table. @param array $privacyfields An associative array of fieldname to description. @param string $summary A description of what the table is used for. @return $this
[ "Function", "to", "add", "a", "database", "table", "which", "contains", "user", "data", "to", "this", "collection", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/privacy/classes/local/metadata/collection.php#L80-L84
212,357
moodle/moodle
privacy/classes/local/metadata/collection.php
collection.add_subsystem_link
public function add_subsystem_link($name, array $privacyfields = [], $summary = '') { $this->add_type(new types\subsystem_link($name, $privacyfields, $summary)); return $this; }
php
public function add_subsystem_link($name, array $privacyfields = [], $summary = '') { $this->add_type(new types\subsystem_link($name, $privacyfields, $summary)); return $this; }
[ "public", "function", "add_subsystem_link", "(", "$", "name", ",", "array", "$", "privacyfields", "=", "[", "]", ",", "$", "summary", "=", "''", ")", "{", "$", "this", "->", "add_type", "(", "new", "types", "\\", "subsystem_link", "(", "$", "name", ",", "$", "privacyfields", ",", "$", "summary", ")", ")", ";", "return", "$", "this", ";", "}" ]
Function to link a subsystem to the component. @param string $name the name of the subsystem to link. @param array $privacyfields An optional associative array of fieldname to description. @param string $summary A description of what is stored within this subsystem. @return $this
[ "Function", "to", "link", "a", "subsystem", "to", "the", "component", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/privacy/classes/local/metadata/collection.php#L94-L98
212,358
moodle/moodle
privacy/classes/local/metadata/collection.php
collection.link_subsystem
public function link_subsystem($name, $summary = '') { $this->add_type(new types\subsystem_link($name, [], $summary)); return $this; }
php
public function link_subsystem($name, $summary = '') { $this->add_type(new types\subsystem_link($name, [], $summary)); return $this; }
[ "public", "function", "link_subsystem", "(", "$", "name", ",", "$", "summary", "=", "''", ")", "{", "$", "this", "->", "add_type", "(", "new", "types", "\\", "subsystem_link", "(", "$", "name", ",", "[", "]", ",", "$", "summary", ")", ")", ";", "return", "$", "this", ";", "}" ]
Old function to link a subsystem to the component. This function is legacy and is not recommended. Please use add_subsystem_link() instead. @param string $name the name of the subsystem to link. @param string $summary A description of what is stored within this subsystem. @return $this
[ "Old", "function", "to", "link", "a", "subsystem", "to", "the", "component", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/privacy/classes/local/metadata/collection.php#L109-L113
212,359
moodle/moodle
privacy/classes/local/metadata/collection.php
collection.add_plugintype_link
public function add_plugintype_link($name, array $privacyfields = [], $summary = '') { $this->add_type(new types\plugintype_link($name, $privacyfields, $summary)); return $this; }
php
public function add_plugintype_link($name, array $privacyfields = [], $summary = '') { $this->add_type(new types\plugintype_link($name, $privacyfields, $summary)); return $this; }
[ "public", "function", "add_plugintype_link", "(", "$", "name", ",", "array", "$", "privacyfields", "=", "[", "]", ",", "$", "summary", "=", "''", ")", "{", "$", "this", "->", "add_type", "(", "new", "types", "\\", "plugintype_link", "(", "$", "name", ",", "$", "privacyfields", ",", "$", "summary", ")", ")", ";", "return", "$", "this", ";", "}" ]
Function to link a plugin to the component. @param string $name the name of the plugin to link. @param array $privacyfields An optional associative array of fieldname to description. @param string $summary A description of what is stored within this plugin. @return $this
[ "Function", "to", "link", "a", "plugin", "to", "the", "component", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/privacy/classes/local/metadata/collection.php#L123-L127
212,360
moodle/moodle
privacy/classes/local/metadata/collection.php
collection.link_plugintype
public function link_plugintype($name, $summary = '') { $this->add_type(new types\plugintype_link($name, [], $summary)); return $this; }
php
public function link_plugintype($name, $summary = '') { $this->add_type(new types\plugintype_link($name, [], $summary)); return $this; }
[ "public", "function", "link_plugintype", "(", "$", "name", ",", "$", "summary", "=", "''", ")", "{", "$", "this", "->", "add_type", "(", "new", "types", "\\", "plugintype_link", "(", "$", "name", ",", "[", "]", ",", "$", "summary", ")", ")", ";", "return", "$", "this", ";", "}" ]
Old function to link a plugin to the component. This function is legacy and is not recommended. Please use add_plugintype_link() instead. @param string $name the name of the plugin to link. @param string $summary A description of what is stored within this plugin. @return $this
[ "Old", "function", "to", "link", "a", "plugin", "to", "the", "component", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/privacy/classes/local/metadata/collection.php#L138-L142
212,361
moodle/moodle
privacy/classes/local/metadata/collection.php
collection.add_external_location_link
public function add_external_location_link($name, array $privacyfields, $summary = '') { $this->add_type(new types\external_location($name, $privacyfields, $summary)); return $this; }
php
public function add_external_location_link($name, array $privacyfields, $summary = '') { $this->add_type(new types\external_location($name, $privacyfields, $summary)); return $this; }
[ "public", "function", "add_external_location_link", "(", "$", "name", ",", "array", "$", "privacyfields", ",", "$", "summary", "=", "''", ")", "{", "$", "this", "->", "add_type", "(", "new", "types", "\\", "external_location", "(", "$", "name", ",", "$", "privacyfields", ",", "$", "summary", ")", ")", ";", "return", "$", "this", ";", "}" ]
Function to indicate that data may be exported to an external location. @param string $name A name for the type of data exported. @param array $privacyfields A list of fields with their description. @param string $summary A description of what the table is used for. This is a language string identifier within the component. @return $this
[ "Function", "to", "indicate", "that", "data", "may", "be", "exported", "to", "an", "external", "location", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/privacy/classes/local/metadata/collection.php#L153-L157
212,362
moodle/moodle
privacy/classes/local/metadata/collection.php
collection.link_external_location
public function link_external_location($name, array $privacyfields, $summary = '') { $this->add_type(new types\external_location($name, $privacyfields, $summary)); return $this; }
php
public function link_external_location($name, array $privacyfields, $summary = '') { $this->add_type(new types\external_location($name, $privacyfields, $summary)); return $this; }
[ "public", "function", "link_external_location", "(", "$", "name", ",", "array", "$", "privacyfields", ",", "$", "summary", "=", "''", ")", "{", "$", "this", "->", "add_type", "(", "new", "types", "\\", "external_location", "(", "$", "name", ",", "$", "privacyfields", ",", "$", "summary", ")", ")", ";", "return", "$", "this", ";", "}" ]
Old function to indicate that data may be exported to an external location. This function is legacy and is not recommended. Please use add_external_location_link() instead. @param string $name A name for the type of data exported. @param array $privacyfields A list of fields with their description. @param string $summary A description of what the table is used for. This is a language string identifier within the component. @return $this
[ "Old", "function", "to", "indicate", "that", "data", "may", "be", "exported", "to", "an", "external", "location", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/privacy/classes/local/metadata/collection.php#L170-L174
212,363
moodle/moodle
privacy/classes/local/metadata/collection.php
collection.add_user_preference
public function add_user_preference($name, $summary = '') { $this->add_type(new types\user_preference($name, $summary)); return $this; }
php
public function add_user_preference($name, $summary = '') { $this->add_type(new types\user_preference($name, $summary)); return $this; }
[ "public", "function", "add_user_preference", "(", "$", "name", ",", "$", "summary", "=", "''", ")", "{", "$", "this", "->", "add_type", "(", "new", "types", "\\", "user_preference", "(", "$", "name", ",", "$", "summary", ")", ")", ";", "return", "$", "this", ";", "}" ]
Add a type of user preference to the collection. Typically this is a single user preference, but in some cases the name of a user preference fits a particular format. @param string $name The name of the user preference. @param string $summary A description of what the preference is used for. @return $this
[ "Add", "a", "type", "of", "user", "preference", "to", "the", "collection", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/privacy/classes/local/metadata/collection.php#L186-L190
212,364
moodle/moodle
question/type/randomsamatch/backup/moodle1/lib.php
moodle1_qtype_randomsamatch_handler.process_question
public function process_question(array $data, array $raw) { // Convert match options. if (isset($data['randomsamatch'])) { $randomsamatch = $data['randomsamatch'][0]; } else { $randomsamatch = array('choose' => 4); } $randomsamatch['id'] = $this->converter->get_nextid(); $randomsamatch['subcats'] = 1; $randomsamatch['correctfeedback'] = ''; $randomsamatch['correctfeedbackformat'] = FORMAT_HTML; $randomsamatch['partiallycorrectfeedback'] = ''; $randomsamatch['partiallycorrectfeedbackformat'] = FORMAT_HTML; $randomsamatch['incorrectfeedback'] = ''; $randomsamatch['incorrectfeedbackformat'] = FORMAT_HTML; $this->write_xml('randomsamatch', $randomsamatch, array('/randomsamatch/id')); }
php
public function process_question(array $data, array $raw) { // Convert match options. if (isset($data['randomsamatch'])) { $randomsamatch = $data['randomsamatch'][0]; } else { $randomsamatch = array('choose' => 4); } $randomsamatch['id'] = $this->converter->get_nextid(); $randomsamatch['subcats'] = 1; $randomsamatch['correctfeedback'] = ''; $randomsamatch['correctfeedbackformat'] = FORMAT_HTML; $randomsamatch['partiallycorrectfeedback'] = ''; $randomsamatch['partiallycorrectfeedbackformat'] = FORMAT_HTML; $randomsamatch['incorrectfeedback'] = ''; $randomsamatch['incorrectfeedbackformat'] = FORMAT_HTML; $this->write_xml('randomsamatch', $randomsamatch, array('/randomsamatch/id')); }
[ "public", "function", "process_question", "(", "array", "$", "data", ",", "array", "$", "raw", ")", "{", "// Convert match options.", "if", "(", "isset", "(", "$", "data", "[", "'randomsamatch'", "]", ")", ")", "{", "$", "randomsamatch", "=", "$", "data", "[", "'randomsamatch'", "]", "[", "0", "]", ";", "}", "else", "{", "$", "randomsamatch", "=", "array", "(", "'choose'", "=>", "4", ")", ";", "}", "$", "randomsamatch", "[", "'id'", "]", "=", "$", "this", "->", "converter", "->", "get_nextid", "(", ")", ";", "$", "randomsamatch", "[", "'subcats'", "]", "=", "1", ";", "$", "randomsamatch", "[", "'correctfeedback'", "]", "=", "''", ";", "$", "randomsamatch", "[", "'correctfeedbackformat'", "]", "=", "FORMAT_HTML", ";", "$", "randomsamatch", "[", "'partiallycorrectfeedback'", "]", "=", "''", ";", "$", "randomsamatch", "[", "'partiallycorrectfeedbackformat'", "]", "=", "FORMAT_HTML", ";", "$", "randomsamatch", "[", "'incorrectfeedback'", "]", "=", "''", ";", "$", "randomsamatch", "[", "'incorrectfeedbackformat'", "]", "=", "FORMAT_HTML", ";", "$", "this", "->", "write_xml", "(", "'randomsamatch'", ",", "$", "randomsamatch", ",", "array", "(", "'/randomsamatch/id'", ")", ")", ";", "}" ]
Appends the randomsamatch specific information to the question. @param array $data grouped question data @param array $raw grouped raw QUESTION data
[ "Appends", "the", "randomsamatch", "specific", "information", "to", "the", "question", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/type/randomsamatch/backup/moodle1/lib.php#L53-L70
212,365
moodle/moodle
backup/util/dbops/backup_plan_dbops.class.php
backup_plan_dbops.get_blockids_from_moduleid
public static function get_blockids_from_moduleid($moduleid) { global $DB; // Get the context of the module $contextid = context_module::instance($moduleid)->id; // Get all the block instances which parentcontextid is the module contextid $blockids = array(); $instances = $DB->get_records('block_instances', array('parentcontextid' => $contextid), '', 'id'); foreach ($instances as $instance) { $blockids[] = $instance->id; } return $blockids; }
php
public static function get_blockids_from_moduleid($moduleid) { global $DB; // Get the context of the module $contextid = context_module::instance($moduleid)->id; // Get all the block instances which parentcontextid is the module contextid $blockids = array(); $instances = $DB->get_records('block_instances', array('parentcontextid' => $contextid), '', 'id'); foreach ($instances as $instance) { $blockids[] = $instance->id; } return $blockids; }
[ "public", "static", "function", "get_blockids_from_moduleid", "(", "$", "moduleid", ")", "{", "global", "$", "DB", ";", "// Get the context of the module", "$", "contextid", "=", "context_module", "::", "instance", "(", "$", "moduleid", ")", "->", "id", ";", "// Get all the block instances which parentcontextid is the module contextid", "$", "blockids", "=", "array", "(", ")", ";", "$", "instances", "=", "$", "DB", "->", "get_records", "(", "'block_instances'", ",", "array", "(", "'parentcontextid'", "=>", "$", "contextid", ")", ",", "''", ",", "'id'", ")", ";", "foreach", "(", "$", "instances", "as", "$", "instance", ")", "{", "$", "blockids", "[", "]", "=", "$", "instance", "->", "id", ";", "}", "return", "$", "blockids", ";", "}" ]
Given one course module id, return one array with all the block intances that belong to it
[ "Given", "one", "course", "module", "id", "return", "one", "array", "with", "all", "the", "block", "intances", "that", "belong", "to", "it" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/util/dbops/backup_plan_dbops.class.php#L38-L51
212,366
moodle/moodle
backup/util/dbops/backup_plan_dbops.class.php
backup_plan_dbops.get_blockids_from_courseid
public static function get_blockids_from_courseid($courseid) { global $DB; // Get the context of the course $contextid = context_course::instance($courseid)->id; // Get all the block instances which parentcontextid is the course contextid $blockids = array(); $instances = $DB->get_records('block_instances', array('parentcontextid' => $contextid), '', 'id'); foreach ($instances as $instance) { $blockids[] = $instance->id; } return $blockids; }
php
public static function get_blockids_from_courseid($courseid) { global $DB; // Get the context of the course $contextid = context_course::instance($courseid)->id; // Get all the block instances which parentcontextid is the course contextid $blockids = array(); $instances = $DB->get_records('block_instances', array('parentcontextid' => $contextid), '', 'id'); foreach ($instances as $instance) { $blockids[] = $instance->id; } return $blockids; }
[ "public", "static", "function", "get_blockids_from_courseid", "(", "$", "courseid", ")", "{", "global", "$", "DB", ";", "// Get the context of the course", "$", "contextid", "=", "context_course", "::", "instance", "(", "$", "courseid", ")", "->", "id", ";", "// Get all the block instances which parentcontextid is the course contextid", "$", "blockids", "=", "array", "(", ")", ";", "$", "instances", "=", "$", "DB", "->", "get_records", "(", "'block_instances'", ",", "array", "(", "'parentcontextid'", "=>", "$", "contextid", ")", ",", "''", ",", "'id'", ")", ";", "foreach", "(", "$", "instances", "as", "$", "instance", ")", "{", "$", "blockids", "[", "]", "=", "$", "instance", "->", "id", ";", "}", "return", "$", "blockids", ";", "}" ]
Given one course id, return one array with all the block intances that belong to it
[ "Given", "one", "course", "id", "return", "one", "array", "with", "all", "the", "block", "intances", "that", "belong", "to", "it" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/util/dbops/backup_plan_dbops.class.php#L56-L69
212,367
moodle/moodle
backup/util/dbops/backup_plan_dbops.class.php
backup_plan_dbops.get_modules_from_sectionid
public static function get_modules_from_sectionid($sectionid) { global $DB; // Get the course and sequence of the section $secrec = $DB->get_record('course_sections', array('id' => $sectionid), 'course, sequence'); $courseid = $secrec->course; $sequence = $secrec->sequence; // Get the section->sequence contents (it roots the activities order) // Get all course modules belonging to requested section $modulesarr = array(); $modules = $DB->get_records_sql(" SELECT cm.id, m.name AS modname FROM {course_modules} cm JOIN {modules} m ON m.id = cm.module WHERE cm.course = ? AND cm.section = ? AND cm.deletioninprogress <> 1", array($courseid, $sectionid)); foreach (explode(',', $sequence) as $moduleid) { if (isset($modules[$moduleid])) { $module = array('id' => $modules[$moduleid]->id, 'modname' => $modules[$moduleid]->modname); $modulesarr[] = (object)$module; unset($modules[$moduleid]); } } if (!empty($modules)) { // This shouldn't happen, but one borked sequence can lead to it. Add the rest foreach ($modules as $module) { $module = array('id' => $module->id, 'modname' => $module->modname); $modulesarr[] = (object)$module; } } return $modulesarr; }
php
public static function get_modules_from_sectionid($sectionid) { global $DB; // Get the course and sequence of the section $secrec = $DB->get_record('course_sections', array('id' => $sectionid), 'course, sequence'); $courseid = $secrec->course; $sequence = $secrec->sequence; // Get the section->sequence contents (it roots the activities order) // Get all course modules belonging to requested section $modulesarr = array(); $modules = $DB->get_records_sql(" SELECT cm.id, m.name AS modname FROM {course_modules} cm JOIN {modules} m ON m.id = cm.module WHERE cm.course = ? AND cm.section = ? AND cm.deletioninprogress <> 1", array($courseid, $sectionid)); foreach (explode(',', $sequence) as $moduleid) { if (isset($modules[$moduleid])) { $module = array('id' => $modules[$moduleid]->id, 'modname' => $modules[$moduleid]->modname); $modulesarr[] = (object)$module; unset($modules[$moduleid]); } } if (!empty($modules)) { // This shouldn't happen, but one borked sequence can lead to it. Add the rest foreach ($modules as $module) { $module = array('id' => $module->id, 'modname' => $module->modname); $modulesarr[] = (object)$module; } } return $modulesarr; }
[ "public", "static", "function", "get_modules_from_sectionid", "(", "$", "sectionid", ")", "{", "global", "$", "DB", ";", "// Get the course and sequence of the section", "$", "secrec", "=", "$", "DB", "->", "get_record", "(", "'course_sections'", ",", "array", "(", "'id'", "=>", "$", "sectionid", ")", ",", "'course, sequence'", ")", ";", "$", "courseid", "=", "$", "secrec", "->", "course", ";", "$", "sequence", "=", "$", "secrec", "->", "sequence", ";", "// Get the section->sequence contents (it roots the activities order)", "// Get all course modules belonging to requested section", "$", "modulesarr", "=", "array", "(", ")", ";", "$", "modules", "=", "$", "DB", "->", "get_records_sql", "(", "\"\n SELECT cm.id, m.name AS modname\n FROM {course_modules} cm\n JOIN {modules} m ON m.id = cm.module\n WHERE cm.course = ?\n AND cm.section = ?\n AND cm.deletioninprogress <> 1\"", ",", "array", "(", "$", "courseid", ",", "$", "sectionid", ")", ")", ";", "foreach", "(", "explode", "(", "','", ",", "$", "sequence", ")", "as", "$", "moduleid", ")", "{", "if", "(", "isset", "(", "$", "modules", "[", "$", "moduleid", "]", ")", ")", "{", "$", "module", "=", "array", "(", "'id'", "=>", "$", "modules", "[", "$", "moduleid", "]", "->", "id", ",", "'modname'", "=>", "$", "modules", "[", "$", "moduleid", "]", "->", "modname", ")", ";", "$", "modulesarr", "[", "]", "=", "(", "object", ")", "$", "module", ";", "unset", "(", "$", "modules", "[", "$", "moduleid", "]", ")", ";", "}", "}", "if", "(", "!", "empty", "(", "$", "modules", ")", ")", "{", "// This shouldn't happen, but one borked sequence can lead to it. Add the rest", "foreach", "(", "$", "modules", "as", "$", "module", ")", "{", "$", "module", "=", "array", "(", "'id'", "=>", "$", "module", "->", "id", ",", "'modname'", "=>", "$", "module", "->", "modname", ")", ";", "$", "modulesarr", "[", "]", "=", "(", "object", ")", "$", "module", ";", "}", "}", "return", "$", "modulesarr", ";", "}" ]
Given one section id, return one array with all the course modules that belong to it
[ "Given", "one", "section", "id", "return", "one", "array", "with", "all", "the", "course", "modules", "that", "belong", "to", "it" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/util/dbops/backup_plan_dbops.class.php#L74-L106
212,368
moodle/moodle
backup/util/dbops/backup_plan_dbops.class.php
backup_plan_dbops.get_sections_from_courseid
public static function get_sections_from_courseid($courseid) { global $DB; // Get all sections belonging to requested course $sectionsarr = array(); $sections = $DB->get_records('course_sections', array('course' => $courseid), 'section'); foreach ($sections as $section) { $sectionsarr[] = $section->id; } return $sectionsarr; }
php
public static function get_sections_from_courseid($courseid) { global $DB; // Get all sections belonging to requested course $sectionsarr = array(); $sections = $DB->get_records('course_sections', array('course' => $courseid), 'section'); foreach ($sections as $section) { $sectionsarr[] = $section->id; } return $sectionsarr; }
[ "public", "static", "function", "get_sections_from_courseid", "(", "$", "courseid", ")", "{", "global", "$", "DB", ";", "// Get all sections belonging to requested course", "$", "sectionsarr", "=", "array", "(", ")", ";", "$", "sections", "=", "$", "DB", "->", "get_records", "(", "'course_sections'", ",", "array", "(", "'course'", "=>", "$", "courseid", ")", ",", "'section'", ")", ";", "foreach", "(", "$", "sections", "as", "$", "section", ")", "{", "$", "sectionsarr", "[", "]", "=", "$", "section", "->", "id", ";", "}", "return", "$", "sectionsarr", ";", "}" ]
Given one course id, return one array with all the course_sections belonging to it
[ "Given", "one", "course", "id", "return", "one", "array", "with", "all", "the", "course_sections", "belonging", "to", "it" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/util/dbops/backup_plan_dbops.class.php#L111-L121
212,369
moodle/moodle
backup/util/dbops/backup_plan_dbops.class.php
backup_plan_dbops.get_default_backup_filename
public static function get_default_backup_filename($format, $type, $id, $users, $anonymised, $useidonly = false) { global $DB; // Calculate backup word $backupword = str_replace(' ', '_', core_text::strtolower(get_string('backupfilename'))); $backupword = trim(clean_filename($backupword), '_'); // Not $useidonly, lets fetch the name $shortname = ''; if (!$useidonly) { // Calculate proper name element (based on type) switch ($type) { case backup::TYPE_1COURSE: $shortname = $DB->get_field('course', 'shortname', array('id' => $id)); $context = context_course::instance($id); $shortname = format_string($shortname, true, array('context' => $context)); break; case backup::TYPE_1SECTION: if (!$shortname = $DB->get_field('course_sections', 'name', array('id' => $id))) { $shortname = $DB->get_field('course_sections', 'section', array('id' => $id)); } break; case backup::TYPE_1ACTIVITY: $cm = get_coursemodule_from_id(null, $id); $shortname = $cm->modname . $id; break; } $shortname = str_replace(' ', '_', $shortname); $shortname = core_text::strtolower(trim(clean_filename($shortname), '_')); } // The name will always contain the ID, but we append the course short name if requested. $name = $id; if (!$useidonly && $shortname != '') { $name .= '-' . $shortname; } // Calculate date $backupdateformat = str_replace(' ', '_', get_string('backupnameformat', 'langconfig')); $date = userdate(time(), $backupdateformat, 99, false); $date = core_text::strtolower(trim(clean_filename($date), '_')); // Calculate info $info = ''; if (!$users) { $info = '-nu'; } else if ($anonymised) { $info = '-an'; } return $backupword . '-' . $format . '-' . $type . '-' . $name . '-' . $date . $info . '.mbz'; }
php
public static function get_default_backup_filename($format, $type, $id, $users, $anonymised, $useidonly = false) { global $DB; // Calculate backup word $backupword = str_replace(' ', '_', core_text::strtolower(get_string('backupfilename'))); $backupword = trim(clean_filename($backupword), '_'); // Not $useidonly, lets fetch the name $shortname = ''; if (!$useidonly) { // Calculate proper name element (based on type) switch ($type) { case backup::TYPE_1COURSE: $shortname = $DB->get_field('course', 'shortname', array('id' => $id)); $context = context_course::instance($id); $shortname = format_string($shortname, true, array('context' => $context)); break; case backup::TYPE_1SECTION: if (!$shortname = $DB->get_field('course_sections', 'name', array('id' => $id))) { $shortname = $DB->get_field('course_sections', 'section', array('id' => $id)); } break; case backup::TYPE_1ACTIVITY: $cm = get_coursemodule_from_id(null, $id); $shortname = $cm->modname . $id; break; } $shortname = str_replace(' ', '_', $shortname); $shortname = core_text::strtolower(trim(clean_filename($shortname), '_')); } // The name will always contain the ID, but we append the course short name if requested. $name = $id; if (!$useidonly && $shortname != '') { $name .= '-' . $shortname; } // Calculate date $backupdateformat = str_replace(' ', '_', get_string('backupnameformat', 'langconfig')); $date = userdate(time(), $backupdateformat, 99, false); $date = core_text::strtolower(trim(clean_filename($date), '_')); // Calculate info $info = ''; if (!$users) { $info = '-nu'; } else if ($anonymised) { $info = '-an'; } return $backupword . '-' . $format . '-' . $type . '-' . $name . '-' . $date . $info . '.mbz'; }
[ "public", "static", "function", "get_default_backup_filename", "(", "$", "format", ",", "$", "type", ",", "$", "id", ",", "$", "users", ",", "$", "anonymised", ",", "$", "useidonly", "=", "false", ")", "{", "global", "$", "DB", ";", "// Calculate backup word", "$", "backupword", "=", "str_replace", "(", "' '", ",", "'_'", ",", "core_text", "::", "strtolower", "(", "get_string", "(", "'backupfilename'", ")", ")", ")", ";", "$", "backupword", "=", "trim", "(", "clean_filename", "(", "$", "backupword", ")", ",", "'_'", ")", ";", "// Not $useidonly, lets fetch the name", "$", "shortname", "=", "''", ";", "if", "(", "!", "$", "useidonly", ")", "{", "// Calculate proper name element (based on type)", "switch", "(", "$", "type", ")", "{", "case", "backup", "::", "TYPE_1COURSE", ":", "$", "shortname", "=", "$", "DB", "->", "get_field", "(", "'course'", ",", "'shortname'", ",", "array", "(", "'id'", "=>", "$", "id", ")", ")", ";", "$", "context", "=", "context_course", "::", "instance", "(", "$", "id", ")", ";", "$", "shortname", "=", "format_string", "(", "$", "shortname", ",", "true", ",", "array", "(", "'context'", "=>", "$", "context", ")", ")", ";", "break", ";", "case", "backup", "::", "TYPE_1SECTION", ":", "if", "(", "!", "$", "shortname", "=", "$", "DB", "->", "get_field", "(", "'course_sections'", ",", "'name'", ",", "array", "(", "'id'", "=>", "$", "id", ")", ")", ")", "{", "$", "shortname", "=", "$", "DB", "->", "get_field", "(", "'course_sections'", ",", "'section'", ",", "array", "(", "'id'", "=>", "$", "id", ")", ")", ";", "}", "break", ";", "case", "backup", "::", "TYPE_1ACTIVITY", ":", "$", "cm", "=", "get_coursemodule_from_id", "(", "null", ",", "$", "id", ")", ";", "$", "shortname", "=", "$", "cm", "->", "modname", ".", "$", "id", ";", "break", ";", "}", "$", "shortname", "=", "str_replace", "(", "' '", ",", "'_'", ",", "$", "shortname", ")", ";", "$", "shortname", "=", "core_text", "::", "strtolower", "(", "trim", "(", "clean_filename", "(", "$", "shortname", ")", ",", "'_'", ")", ")", ";", "}", "// The name will always contain the ID, but we append the course short name if requested.", "$", "name", "=", "$", "id", ";", "if", "(", "!", "$", "useidonly", "&&", "$", "shortname", "!=", "''", ")", "{", "$", "name", ".=", "'-'", ".", "$", "shortname", ";", "}", "// Calculate date", "$", "backupdateformat", "=", "str_replace", "(", "' '", ",", "'_'", ",", "get_string", "(", "'backupnameformat'", ",", "'langconfig'", ")", ")", ";", "$", "date", "=", "userdate", "(", "time", "(", ")", ",", "$", "backupdateformat", ",", "99", ",", "false", ")", ";", "$", "date", "=", "core_text", "::", "strtolower", "(", "trim", "(", "clean_filename", "(", "$", "date", ")", ",", "'_'", ")", ")", ";", "// Calculate info", "$", "info", "=", "''", ";", "if", "(", "!", "$", "users", ")", "{", "$", "info", "=", "'-nu'", ";", "}", "else", "if", "(", "$", "anonymised", ")", "{", "$", "info", "=", "'-an'", ";", "}", "return", "$", "backupword", ".", "'-'", ".", "$", "format", ".", "'-'", ".", "$", "type", ".", "'-'", ".", "$", "name", ".", "'-'", ".", "$", "date", ".", "$", "info", ".", "'.mbz'", ";", "}" ]
Returns the default backup filename, based in passed params. Default format is (see MDL-22145) backup word - format - type - name - date - info . mbz where name is variable (course shortname, section name/id, activity modulename + cmid) and info can be (nu = no user info, an = anonymized). The last param $useidasname, defaulting to false, allows to replace the course shortname by the course id (used by automated backups, to avoid non-ascii chars in OS filesystem) @param string $format One of backup::FORMAT_ @param string $type One of backup::TYPE_ @param int $courseid/$sectionid/$cmid @param bool $users Should be true is users were included in the backup @param bool $anonymised Should be true is user information was anonymized. @param bool $useidonly only use the ID in the file name @return string The filename to use
[ "Returns", "the", "default", "backup", "filename", "based", "in", "passed", "params", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/util/dbops/backup_plan_dbops.class.php#L204-L256
212,370
moodle/moodle
backup/util/dbops/backup_plan_dbops.class.php
backup_plan_dbops.require_gradebook_backup
public static function require_gradebook_backup($courseid, $backupid) { global $DB; $sql = "SELECT count(id) FROM {grade_items} WHERE courseid=:courseid AND itemtype = 'mod' AND id NOT IN ( SELECT bi.itemid FROM {backup_ids_temp} bi WHERE bi.itemname = 'grade_itemfinal' AND bi.backupid = :backupid)"; $params = array('courseid'=>$courseid, 'backupid'=>$backupid); $count = $DB->count_records_sql($sql, $params); //if there are 0 activity grade items not already included in the backup return $count == 0; }
php
public static function require_gradebook_backup($courseid, $backupid) { global $DB; $sql = "SELECT count(id) FROM {grade_items} WHERE courseid=:courseid AND itemtype = 'mod' AND id NOT IN ( SELECT bi.itemid FROM {backup_ids_temp} bi WHERE bi.itemname = 'grade_itemfinal' AND bi.backupid = :backupid)"; $params = array('courseid'=>$courseid, 'backupid'=>$backupid); $count = $DB->count_records_sql($sql, $params); //if there are 0 activity grade items not already included in the backup return $count == 0; }
[ "public", "static", "function", "require_gradebook_backup", "(", "$", "courseid", ",", "$", "backupid", ")", "{", "global", "$", "DB", ";", "$", "sql", "=", "\"SELECT count(id)\n FROM {grade_items}\n WHERE courseid=:courseid\n AND itemtype = 'mod'\n AND id NOT IN (\n SELECT bi.itemid\n FROM {backup_ids_temp} bi\n WHERE bi.itemname = 'grade_itemfinal'\n AND bi.backupid = :backupid)\"", ";", "$", "params", "=", "array", "(", "'courseid'", "=>", "$", "courseid", ",", "'backupid'", "=>", "$", "backupid", ")", ";", "$", "count", "=", "$", "DB", "->", "count_records_sql", "(", "$", "sql", ",", "$", "params", ")", ";", "//if there are 0 activity grade items not already included in the backup", "return", "$", "count", "==", "0", ";", "}" ]
Returns a flag indicating the need to backup gradebook elements like calculated grade items and category visibility If all activity related grade items are being backed up we can also backup calculated grade items and categories
[ "Returns", "a", "flag", "indicating", "the", "need", "to", "backup", "gradebook", "elements", "like", "calculated", "grade", "items", "and", "category", "visibility", "If", "all", "activity", "related", "grade", "items", "are", "being", "backed", "up", "we", "can", "also", "backup", "calculated", "grade", "items", "and", "categories" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/util/dbops/backup_plan_dbops.class.php#L262-L281
212,371
moodle/moodle
cache/classes/dummystore.php
cachestore_dummy.initialise
public function initialise(cache_definition $definition) { // If the definition isn't using static acceleration then we need to be store data here. // The reasoning behind this is that: // - If the definition is using static acceleration then the cache loader is going to // store things in its static array. // - If the definition is not using static acceleration then the cache loader won't try to store anything // and we will need to store it here in order to make sure it is accessible. if ($definition->get_mode() !== self::MODE_APPLICATION) { // Neither the request cache nor the session cache provide static acceleration. $this->persist = true; } else { $this->persist = !$definition->use_static_acceleration(); } }
php
public function initialise(cache_definition $definition) { // If the definition isn't using static acceleration then we need to be store data here. // The reasoning behind this is that: // - If the definition is using static acceleration then the cache loader is going to // store things in its static array. // - If the definition is not using static acceleration then the cache loader won't try to store anything // and we will need to store it here in order to make sure it is accessible. if ($definition->get_mode() !== self::MODE_APPLICATION) { // Neither the request cache nor the session cache provide static acceleration. $this->persist = true; } else { $this->persist = !$definition->use_static_acceleration(); } }
[ "public", "function", "initialise", "(", "cache_definition", "$", "definition", ")", "{", "// If the definition isn't using static acceleration then we need to be store data here.", "// The reasoning behind this is that:", "// - If the definition is using static acceleration then the cache loader is going to", "// store things in its static array.", "// - If the definition is not using static acceleration then the cache loader won't try to store anything", "// and we will need to store it here in order to make sure it is accessible.", "if", "(", "$", "definition", "->", "get_mode", "(", ")", "!==", "self", "::", "MODE_APPLICATION", ")", "{", "// Neither the request cache nor the session cache provide static acceleration.", "$", "this", "->", "persist", "=", "true", ";", "}", "else", "{", "$", "this", "->", "persist", "=", "!", "$", "definition", "->", "use_static_acceleration", "(", ")", ";", "}", "}" ]
Initialises the store instance for a definition. @param cache_definition $definition
[ "Initialises", "the", "store", "instance", "for", "a", "definition", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cache/classes/dummystore.php#L109-L122
212,372
moodle/moodle
cache/classes/dummystore.php
cachestore_dummy.get
public function get($key) { if ($this->persist && array_key_exists($key, $this->store)) { return $this->store[$key]; } return false; }
php
public function get($key) { if ($this->persist && array_key_exists($key, $this->store)) { return $this->store[$key]; } return false; }
[ "public", "function", "get", "(", "$", "key", ")", "{", "if", "(", "$", "this", "->", "persist", "&&", "array_key_exists", "(", "$", "key", ",", "$", "this", "->", "store", ")", ")", "{", "return", "$", "this", "->", "store", "[", "$", "key", "]", ";", "}", "return", "false", ";", "}" ]
Returns the data for the given key @param string $key @return string|false
[ "Returns", "the", "data", "for", "the", "given", "key" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cache/classes/dummystore.php#L146-L151
212,373
moodle/moodle
cache/classes/dummystore.php
cachestore_dummy.get_many
public function get_many($keys) { $return = array(); foreach ($keys as $key) { if ($this->persist && array_key_exists($key, $this->store)) { $return[$key] = $this->store[$key]; } else { $return[$key] = false; } } return $return; }
php
public function get_many($keys) { $return = array(); foreach ($keys as $key) { if ($this->persist && array_key_exists($key, $this->store)) { $return[$key] = $this->store[$key]; } else { $return[$key] = false; } } return $return; }
[ "public", "function", "get_many", "(", "$", "keys", ")", "{", "$", "return", "=", "array", "(", ")", ";", "foreach", "(", "$", "keys", "as", "$", "key", ")", "{", "if", "(", "$", "this", "->", "persist", "&&", "array_key_exists", "(", "$", "key", ",", "$", "this", "->", "store", ")", ")", "{", "$", "return", "[", "$", "key", "]", "=", "$", "this", "->", "store", "[", "$", "key", "]", ";", "}", "else", "{", "$", "return", "[", "$", "key", "]", "=", "false", ";", "}", "}", "return", "$", "return", ";", "}" ]
Gets' the values for many keys @param array $keys @return bool
[ "Gets", "the", "values", "for", "many", "keys" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cache/classes/dummystore.php#L158-L168
212,374
moodle/moodle
cache/classes/dummystore.php
cachestore_dummy.set
public function set($key, $data) { if ($this->persist) { $this->store[$key] = $data; } return true; }
php
public function set($key, $data) { if ($this->persist) { $this->store[$key] = $data; } return true; }
[ "public", "function", "set", "(", "$", "key", ",", "$", "data", ")", "{", "if", "(", "$", "this", "->", "persist", ")", "{", "$", "this", "->", "store", "[", "$", "key", "]", "=", "$", "data", ";", "}", "return", "true", ";", "}" ]
Sets an item in the cache @param string $key @param mixed $data @return bool
[ "Sets", "an", "item", "in", "the", "cache" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cache/classes/dummystore.php#L176-L181
212,375
moodle/moodle
cache/classes/dummystore.php
cachestore_dummy.set_many
public function set_many(array $keyvaluearray) { if ($this->persist) { foreach ($keyvaluearray as $pair) { $this->store[$pair['key']] = $pair['value']; } } return count($keyvaluearray); }
php
public function set_many(array $keyvaluearray) { if ($this->persist) { foreach ($keyvaluearray as $pair) { $this->store[$pair['key']] = $pair['value']; } } return count($keyvaluearray); }
[ "public", "function", "set_many", "(", "array", "$", "keyvaluearray", ")", "{", "if", "(", "$", "this", "->", "persist", ")", "{", "foreach", "(", "$", "keyvaluearray", "as", "$", "pair", ")", "{", "$", "this", "->", "store", "[", "$", "pair", "[", "'key'", "]", "]", "=", "$", "pair", "[", "'value'", "]", ";", "}", "}", "return", "count", "(", "$", "keyvaluearray", ")", ";", "}" ]
Sets many items in the cache @param array $keyvaluearray @return int
[ "Sets", "many", "items", "in", "the", "cache" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cache/classes/dummystore.php#L188-L196
212,376
moodle/moodle
cache/classes/dummystore.php
cachestore_dummy.delete_many
public function delete_many(array $keys) { if ($this->persist) { foreach ($keys as $key) { unset($this->store[$key]); } } return count($keys); }
php
public function delete_many(array $keys) { if ($this->persist) { foreach ($keys as $key) { unset($this->store[$key]); } } return count($keys); }
[ "public", "function", "delete_many", "(", "array", "$", "keys", ")", "{", "if", "(", "$", "this", "->", "persist", ")", "{", "foreach", "(", "$", "keys", "as", "$", "key", ")", "{", "unset", "(", "$", "this", "->", "store", "[", "$", "key", "]", ")", ";", "}", "}", "return", "count", "(", "$", "keys", ")", ";", "}" ]
Deletes many items from the cache @param array $keys @return bool
[ "Deletes", "many", "items", "from", "the", "cache" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cache/classes/dummystore.php#L212-L219
212,377
moodle/moodle
lib/form/dateselector.php
MoodleQuickForm_date_selector.exportValue
function exportValue(&$submitValues, $assoc = false) { $valuearray = array(); foreach ($this->_elements as $element){ $thisexport = $element->exportValue($submitValues[$this->getName()], true); if ($thisexport!=null){ $valuearray += $thisexport; } } if (count($valuearray) && isset($valuearray['year'])) { if($this->_options['optional']) { // If checkbox is on, the value is zero, so go no further if(empty($valuearray['enabled'])) { return $this->_prepareValue(0, $assoc); } } // Get the calendar type used - see MDL-18375. $calendartype = \core_calendar\type_factory::get_calendar_instance(); $gregoriandate = $calendartype->convert_to_gregorian($valuearray['year'], $valuearray['month'], $valuearray['day']); $value = make_timestamp($gregoriandate['year'], $gregoriandate['month'], $gregoriandate['day'], 0, 0, 0, $this->_options['timezone'], true); return $this->_prepareValue($value, $assoc); } else { return null; } }
php
function exportValue(&$submitValues, $assoc = false) { $valuearray = array(); foreach ($this->_elements as $element){ $thisexport = $element->exportValue($submitValues[$this->getName()], true); if ($thisexport!=null){ $valuearray += $thisexport; } } if (count($valuearray) && isset($valuearray['year'])) { if($this->_options['optional']) { // If checkbox is on, the value is zero, so go no further if(empty($valuearray['enabled'])) { return $this->_prepareValue(0, $assoc); } } // Get the calendar type used - see MDL-18375. $calendartype = \core_calendar\type_factory::get_calendar_instance(); $gregoriandate = $calendartype->convert_to_gregorian($valuearray['year'], $valuearray['month'], $valuearray['day']); $value = make_timestamp($gregoriandate['year'], $gregoriandate['month'], $gregoriandate['day'], 0, 0, 0, $this->_options['timezone'], true); return $this->_prepareValue($value, $assoc); } else { return null; } }
[ "function", "exportValue", "(", "&", "$", "submitValues", ",", "$", "assoc", "=", "false", ")", "{", "$", "valuearray", "=", "array", "(", ")", ";", "foreach", "(", "$", "this", "->", "_elements", "as", "$", "element", ")", "{", "$", "thisexport", "=", "$", "element", "->", "exportValue", "(", "$", "submitValues", "[", "$", "this", "->", "getName", "(", ")", "]", ",", "true", ")", ";", "if", "(", "$", "thisexport", "!=", "null", ")", "{", "$", "valuearray", "+=", "$", "thisexport", ";", "}", "}", "if", "(", "count", "(", "$", "valuearray", ")", "&&", "isset", "(", "$", "valuearray", "[", "'year'", "]", ")", ")", "{", "if", "(", "$", "this", "->", "_options", "[", "'optional'", "]", ")", "{", "// If checkbox is on, the value is zero, so go no further", "if", "(", "empty", "(", "$", "valuearray", "[", "'enabled'", "]", ")", ")", "{", "return", "$", "this", "->", "_prepareValue", "(", "0", ",", "$", "assoc", ")", ";", "}", "}", "// Get the calendar type used - see MDL-18375.", "$", "calendartype", "=", "\\", "core_calendar", "\\", "type_factory", "::", "get_calendar_instance", "(", ")", ";", "$", "gregoriandate", "=", "$", "calendartype", "->", "convert_to_gregorian", "(", "$", "valuearray", "[", "'year'", "]", ",", "$", "valuearray", "[", "'month'", "]", ",", "$", "valuearray", "[", "'day'", "]", ")", ";", "$", "value", "=", "make_timestamp", "(", "$", "gregoriandate", "[", "'year'", "]", ",", "$", "gregoriandate", "[", "'month'", "]", ",", "$", "gregoriandate", "[", "'day'", "]", ",", "0", ",", "0", ",", "0", ",", "$", "this", "->", "_options", "[", "'timezone'", "]", ",", "true", ")", ";", "return", "$", "this", "->", "_prepareValue", "(", "$", "value", ",", "$", "assoc", ")", ";", "}", "else", "{", "return", "null", ";", "}", "}" ]
Output a timestamp. Give it the name of the group. @param array $submitValues values submitted. @param bool $assoc specifies if returned array is associative @return array
[ "Output", "a", "timestamp", ".", "Give", "it", "the", "name", "of", "the", "group", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/form/dateselector.php#L269-L298
212,378
moodle/moodle
lib/dtl/xml_database_exporter.php
xml_database_exporter.begin_database_export
public function begin_database_export($version, $release, $timestamp, $description) { $this->output('<?xml version="1.0" encoding="utf-8"?>'); //TODO add xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" and schema information $this->output('<moodle_database version="'.$version.'" release="'.$release.'" timestamp="'.$timestamp.'"'.(empty ($description) ? '' : ' comment="'.htmlspecialchars($description, ENT_QUOTES, 'UTF-8').'"').'>'); }
php
public function begin_database_export($version, $release, $timestamp, $description) { $this->output('<?xml version="1.0" encoding="utf-8"?>'); //TODO add xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" and schema information $this->output('<moodle_database version="'.$version.'" release="'.$release.'" timestamp="'.$timestamp.'"'.(empty ($description) ? '' : ' comment="'.htmlspecialchars($description, ENT_QUOTES, 'UTF-8').'"').'>'); }
[ "public", "function", "begin_database_export", "(", "$", "version", ",", "$", "release", ",", "$", "timestamp", ",", "$", "description", ")", "{", "$", "this", "->", "output", "(", "'<?xml version=\"1.0\" encoding=\"utf-8\"?>'", ")", ";", "//TODO add xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" and schema information", "$", "this", "->", "output", "(", "'<moodle_database version=\"'", ".", "$", "version", ".", "'\" release=\"'", ".", "$", "release", ".", "'\" timestamp=\"'", ".", "$", "timestamp", ".", "'\"'", ".", "(", "empty", "(", "$", "description", ")", "?", "''", ":", "' comment=\"'", ".", "htmlspecialchars", "(", "$", "description", ",", "ENT_QUOTES", ",", "'UTF-8'", ")", ".", "'\"'", ")", ".", "'>'", ")", ";", "}" ]
Callback function. Outputs open XML PI and moodle_database opening tag. @param float $version the version of the system which generating the data @param string $release moodle release info @param string $timestamp the timestamp of the data (in ISO 8601) format. @param string $description a user description of the data. @return void
[ "Callback", "function", ".", "Outputs", "open", "XML", "PI", "and", "moodle_database", "opening", "tag", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/dtl/xml_database_exporter.php#L48-L52
212,379
moodle/moodle
lib/dtl/xml_database_exporter.php
xml_database_exporter.export_table_data
public function export_table_data(xmldb_table $table, $data) { $this->output('<record>'); foreach ($data as $key => $value) { if (is_null($value)) { $this->output('<field name="'.$key.'" value="null" />'); } else { $this->output('<field name="'.$key.'">'.htmlspecialchars($value, ENT_NOQUOTES, 'UTF-8').'</field>'); } } $this->output('</record>'); }
php
public function export_table_data(xmldb_table $table, $data) { $this->output('<record>'); foreach ($data as $key => $value) { if (is_null($value)) { $this->output('<field name="'.$key.'" value="null" />'); } else { $this->output('<field name="'.$key.'">'.htmlspecialchars($value, ENT_NOQUOTES, 'UTF-8').'</field>'); } } $this->output('</record>'); }
[ "public", "function", "export_table_data", "(", "xmldb_table", "$", "table", ",", "$", "data", ")", "{", "$", "this", "->", "output", "(", "'<record>'", ")", ";", "foreach", "(", "$", "data", "as", "$", "key", "=>", "$", "value", ")", "{", "if", "(", "is_null", "(", "$", "value", ")", ")", "{", "$", "this", "->", "output", "(", "'<field name=\"'", ".", "$", "key", ".", "'\" value=\"null\" />'", ")", ";", "}", "else", "{", "$", "this", "->", "output", "(", "'<field name=\"'", ".", "$", "key", ".", "'\">'", ".", "htmlspecialchars", "(", "$", "value", ",", "ENT_NOQUOTES", ",", "'UTF-8'", ")", ".", "'</field>'", ")", ";", "}", "}", "$", "this", "->", "output", "(", "'</record>'", ")", ";", "}" ]
Callback function. Outputs record tag with field subtags and data. @param xmldb_table $table - XMLDB object of the table from which data was retrieved @param object $data - data object (fields and values from record) @return void
[ "Callback", "function", ".", "Outputs", "record", "tag", "with", "field", "subtags", "and", "data", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/dtl/xml_database_exporter.php#L87-L97
212,380
moodle/moodle
lib/horde/framework/Horde/Idna.php
Horde_Idna._getBackend
protected static function _getBackend() { if (!isset(self::$_backend)) { if (extension_loaded('intl')) { /* Only available in PHP > 5.4.0 */ self::$_backend = defined('INTL_IDNA_VARIANT_UTS46') ? 'INTL_UTS46' : 'INTL'; } else { self::$_backend = new Horde_Idna_Punycode(); } } return self::$_backend; }
php
protected static function _getBackend() { if (!isset(self::$_backend)) { if (extension_loaded('intl')) { /* Only available in PHP > 5.4.0 */ self::$_backend = defined('INTL_IDNA_VARIANT_UTS46') ? 'INTL_UTS46' : 'INTL'; } else { self::$_backend = new Horde_Idna_Punycode(); } } return self::$_backend; }
[ "protected", "static", "function", "_getBackend", "(", ")", "{", "if", "(", "!", "isset", "(", "self", "::", "$", "_backend", ")", ")", "{", "if", "(", "extension_loaded", "(", "'intl'", ")", ")", "{", "/* Only available in PHP > 5.4.0 */", "self", "::", "$", "_backend", "=", "defined", "(", "'INTL_IDNA_VARIANT_UTS46'", ")", "?", "'INTL_UTS46'", ":", "'INTL'", ";", "}", "else", "{", "self", "::", "$", "_backend", "=", "new", "Horde_Idna_Punycode", "(", ")", ";", "}", "}", "return", "self", "::", "$", "_backend", ";", "}" ]
Return the IDNA backend. @return mixed IDNA backend (false if none available).
[ "Return", "the", "IDNA", "backend", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/horde/framework/Horde/Idna.php#L153-L167
212,381
moodle/moodle
repository/url/lib.php
repository_url.escape_url
protected function escape_url($url) { $url = str_replace('"', '%22', $url); $url = str_replace('\'', '%27', $url); $url = str_replace(' ', '%20', $url); $url = str_replace('<', '%3C', $url); $url = str_replace('>', '%3E', $url); return $url; }
php
protected function escape_url($url) { $url = str_replace('"', '%22', $url); $url = str_replace('\'', '%27', $url); $url = str_replace(' ', '%20', $url); $url = str_replace('<', '%3C', $url); $url = str_replace('>', '%3E', $url); return $url; }
[ "protected", "function", "escape_url", "(", "$", "url", ")", "{", "$", "url", "=", "str_replace", "(", "'\"'", ",", "'%22'", ",", "$", "url", ")", ";", "$", "url", "=", "str_replace", "(", "'\\''", ",", "'%27'", ",", "$", "url", ")", ";", "$", "url", "=", "str_replace", "(", "' '", ",", "'%20'", ",", "$", "url", ")", ";", "$", "url", "=", "str_replace", "(", "'<'", ",", "'%3C'", ",", "$", "url", ")", ";", "$", "url", "=", "str_replace", "(", "'>'", ",", "'%3E'", ",", "$", "url", ")", ";", "return", "$", "url", ";", "}" ]
Escapes a url by replacing spaces with %20. Note: In general moodle does not automatically escape urls, but for the purposes of making this plugin more user friendly and make it consistent with some other areas in moodle (such as mod_url), urls will automatically be escaped. If moodle_url or PARAM_URL is changed to clean characters that need to be escaped, then this function can be removed @param string $url An unescaped url. @return string The escaped url
[ "Escapes", "a", "url", "by", "replacing", "spaces", "with", "%20", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/repository/url/lib.php#L236-L243
212,382
moodle/moodle
mod/wiki/classes/external.php
mod_wiki_external.get_wikis_by_courses
public static function get_wikis_by_courses($courseids = array()) { $returnedwikis = array(); $warnings = array(); $params = self::validate_parameters(self::get_wikis_by_courses_parameters(), array('courseids' => $courseids)); $mycourses = array(); if (empty($params['courseids'])) { $mycourses = enrol_get_my_courses(); $params['courseids'] = array_keys($mycourses); } // Ensure there are courseids to loop through. if (!empty($params['courseids'])) { list($courses, $warnings) = external_util::validate_courses($params['courseids'], $mycourses); // Get the wikis in this course, this function checks users visibility permissions. // We can avoid then additional validate_context calls. $wikis = get_all_instances_in_courses('wiki', $courses); foreach ($wikis as $wiki) { $context = context_module::instance($wiki->coursemodule); // Entry to return. $module = array(); // First, we return information that any user can see in (or can deduce from) the web interface. $module['id'] = $wiki->id; $module['coursemodule'] = $wiki->coursemodule; $module['course'] = $wiki->course; $module['name'] = external_format_string($wiki->name, $context->id); $viewablefields = []; if (has_capability('mod/wiki:viewpage', $context)) { list($module['intro'], $module['introformat']) = external_format_text($wiki->intro, $wiki->introformat, $context->id, 'mod_wiki', 'intro', null); $module['introfiles'] = external_util::get_area_files($context->id, 'mod_wiki', 'intro', false, false); $viewablefields = array('firstpagetitle', 'wikimode', 'defaultformat', 'forceformat', 'editbegin', 'editend', 'section', 'visible', 'groupmode', 'groupingid'); } // Check additional permissions for returning optional private settings. if (has_capability('moodle/course:manageactivities', $context)) { $additionalfields = array('timecreated', 'timemodified'); $viewablefields = array_merge($viewablefields, $additionalfields); } foreach ($viewablefields as $field) { $module[$field] = $wiki->{$field}; } // Check if user can add new pages. $module['cancreatepages'] = wiki_can_create_pages($context); $returnedwikis[] = $module; } } $result = array(); $result['wikis'] = $returnedwikis; $result['warnings'] = $warnings; return $result; }
php
public static function get_wikis_by_courses($courseids = array()) { $returnedwikis = array(); $warnings = array(); $params = self::validate_parameters(self::get_wikis_by_courses_parameters(), array('courseids' => $courseids)); $mycourses = array(); if (empty($params['courseids'])) { $mycourses = enrol_get_my_courses(); $params['courseids'] = array_keys($mycourses); } // Ensure there are courseids to loop through. if (!empty($params['courseids'])) { list($courses, $warnings) = external_util::validate_courses($params['courseids'], $mycourses); // Get the wikis in this course, this function checks users visibility permissions. // We can avoid then additional validate_context calls. $wikis = get_all_instances_in_courses('wiki', $courses); foreach ($wikis as $wiki) { $context = context_module::instance($wiki->coursemodule); // Entry to return. $module = array(); // First, we return information that any user can see in (or can deduce from) the web interface. $module['id'] = $wiki->id; $module['coursemodule'] = $wiki->coursemodule; $module['course'] = $wiki->course; $module['name'] = external_format_string($wiki->name, $context->id); $viewablefields = []; if (has_capability('mod/wiki:viewpage', $context)) { list($module['intro'], $module['introformat']) = external_format_text($wiki->intro, $wiki->introformat, $context->id, 'mod_wiki', 'intro', null); $module['introfiles'] = external_util::get_area_files($context->id, 'mod_wiki', 'intro', false, false); $viewablefields = array('firstpagetitle', 'wikimode', 'defaultformat', 'forceformat', 'editbegin', 'editend', 'section', 'visible', 'groupmode', 'groupingid'); } // Check additional permissions for returning optional private settings. if (has_capability('moodle/course:manageactivities', $context)) { $additionalfields = array('timecreated', 'timemodified'); $viewablefields = array_merge($viewablefields, $additionalfields); } foreach ($viewablefields as $field) { $module[$field] = $wiki->{$field}; } // Check if user can add new pages. $module['cancreatepages'] = wiki_can_create_pages($context); $returnedwikis[] = $module; } } $result = array(); $result['wikis'] = $returnedwikis; $result['warnings'] = $warnings; return $result; }
[ "public", "static", "function", "get_wikis_by_courses", "(", "$", "courseids", "=", "array", "(", ")", ")", "{", "$", "returnedwikis", "=", "array", "(", ")", ";", "$", "warnings", "=", "array", "(", ")", ";", "$", "params", "=", "self", "::", "validate_parameters", "(", "self", "::", "get_wikis_by_courses_parameters", "(", ")", ",", "array", "(", "'courseids'", "=>", "$", "courseids", ")", ")", ";", "$", "mycourses", "=", "array", "(", ")", ";", "if", "(", "empty", "(", "$", "params", "[", "'courseids'", "]", ")", ")", "{", "$", "mycourses", "=", "enrol_get_my_courses", "(", ")", ";", "$", "params", "[", "'courseids'", "]", "=", "array_keys", "(", "$", "mycourses", ")", ";", "}", "// Ensure there are courseids to loop through.", "if", "(", "!", "empty", "(", "$", "params", "[", "'courseids'", "]", ")", ")", "{", "list", "(", "$", "courses", ",", "$", "warnings", ")", "=", "external_util", "::", "validate_courses", "(", "$", "params", "[", "'courseids'", "]", ",", "$", "mycourses", ")", ";", "// Get the wikis in this course, this function checks users visibility permissions.", "// We can avoid then additional validate_context calls.", "$", "wikis", "=", "get_all_instances_in_courses", "(", "'wiki'", ",", "$", "courses", ")", ";", "foreach", "(", "$", "wikis", "as", "$", "wiki", ")", "{", "$", "context", "=", "context_module", "::", "instance", "(", "$", "wiki", "->", "coursemodule", ")", ";", "// Entry to return.", "$", "module", "=", "array", "(", ")", ";", "// First, we return information that any user can see in (or can deduce from) the web interface.", "$", "module", "[", "'id'", "]", "=", "$", "wiki", "->", "id", ";", "$", "module", "[", "'coursemodule'", "]", "=", "$", "wiki", "->", "coursemodule", ";", "$", "module", "[", "'course'", "]", "=", "$", "wiki", "->", "course", ";", "$", "module", "[", "'name'", "]", "=", "external_format_string", "(", "$", "wiki", "->", "name", ",", "$", "context", "->", "id", ")", ";", "$", "viewablefields", "=", "[", "]", ";", "if", "(", "has_capability", "(", "'mod/wiki:viewpage'", ",", "$", "context", ")", ")", "{", "list", "(", "$", "module", "[", "'intro'", "]", ",", "$", "module", "[", "'introformat'", "]", ")", "=", "external_format_text", "(", "$", "wiki", "->", "intro", ",", "$", "wiki", "->", "introformat", ",", "$", "context", "->", "id", ",", "'mod_wiki'", ",", "'intro'", ",", "null", ")", ";", "$", "module", "[", "'introfiles'", "]", "=", "external_util", "::", "get_area_files", "(", "$", "context", "->", "id", ",", "'mod_wiki'", ",", "'intro'", ",", "false", ",", "false", ")", ";", "$", "viewablefields", "=", "array", "(", "'firstpagetitle'", ",", "'wikimode'", ",", "'defaultformat'", ",", "'forceformat'", ",", "'editbegin'", ",", "'editend'", ",", "'section'", ",", "'visible'", ",", "'groupmode'", ",", "'groupingid'", ")", ";", "}", "// Check additional permissions for returning optional private settings.", "if", "(", "has_capability", "(", "'moodle/course:manageactivities'", ",", "$", "context", ")", ")", "{", "$", "additionalfields", "=", "array", "(", "'timecreated'", ",", "'timemodified'", ")", ";", "$", "viewablefields", "=", "array_merge", "(", "$", "viewablefields", ",", "$", "additionalfields", ")", ";", "}", "foreach", "(", "$", "viewablefields", "as", "$", "field", ")", "{", "$", "module", "[", "$", "field", "]", "=", "$", "wiki", "->", "{", "$", "field", "}", ";", "}", "// Check if user can add new pages.", "$", "module", "[", "'cancreatepages'", "]", "=", "wiki_can_create_pages", "(", "$", "context", ")", ";", "$", "returnedwikis", "[", "]", "=", "$", "module", ";", "}", "}", "$", "result", "=", "array", "(", ")", ";", "$", "result", "[", "'wikis'", "]", "=", "$", "returnedwikis", ";", "$", "result", "[", "'warnings'", "]", "=", "$", "warnings", ";", "return", "$", "result", ";", "}" ]
Returns a list of wikis in a provided list of courses, if no list is provided all wikis that the user can view will be returned. @param array $courseids The courses IDs. @return array Containing a list of warnings and a list of wikis. @since Moodle 3.1
[ "Returns", "a", "list", "of", "wikis", "in", "a", "provided", "list", "of", "courses", "if", "no", "list", "is", "provided", "all", "wikis", "that", "the", "user", "can", "view", "will", "be", "returned", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/wiki/classes/external.php#L68-L134
212,383
moodle/moodle
mod/wiki/classes/external.php
mod_wiki_external.get_wikis_by_courses_returns
public static function get_wikis_by_courses_returns() { return new external_single_structure( array( 'wikis' => new external_multiple_structure( new external_single_structure( array( 'id' => new external_value(PARAM_INT, 'Wiki ID.'), 'coursemodule' => new external_value(PARAM_INT, 'Course module ID.'), 'course' => new external_value(PARAM_INT, 'Course ID.'), 'name' => new external_value(PARAM_RAW, 'Wiki name.'), 'intro' => new external_value(PARAM_RAW, 'Wiki intro.', VALUE_OPTIONAL), 'introformat' => new external_format_value('Wiki intro format.', VALUE_OPTIONAL), 'introfiles' => new external_files('Files in the introduction text', VALUE_OPTIONAL), 'timecreated' => new external_value(PARAM_INT, 'Time of creation.', VALUE_OPTIONAL), 'timemodified' => new external_value(PARAM_INT, 'Time of last modification.', VALUE_OPTIONAL), 'firstpagetitle' => new external_value(PARAM_RAW, 'First page title.', VALUE_OPTIONAL), 'wikimode' => new external_value(PARAM_TEXT, 'Wiki mode (individual, collaborative).', VALUE_OPTIONAL), 'defaultformat' => new external_value(PARAM_TEXT, 'Wiki\'s default format (html, creole, nwiki).', VALUE_OPTIONAL), 'forceformat' => new external_value(PARAM_INT, '1 if format is forced, 0 otherwise.', VALUE_OPTIONAL), 'editbegin' => new external_value(PARAM_INT, 'Edit begin.', VALUE_OPTIONAL), 'editend' => new external_value(PARAM_INT, 'Edit end.', VALUE_OPTIONAL), 'section' => new external_value(PARAM_INT, 'Course section ID.', VALUE_OPTIONAL), 'visible' => new external_value(PARAM_INT, '1 if visible, 0 otherwise.', VALUE_OPTIONAL), 'groupmode' => new external_value(PARAM_INT, 'Group mode.', VALUE_OPTIONAL), 'groupingid' => new external_value(PARAM_INT, 'Group ID.', VALUE_OPTIONAL), 'cancreatepages' => new external_value(PARAM_BOOL, 'True if user can create pages.'), ), 'Wikis' ) ), 'warnings' => new external_warnings(), ) ); }
php
public static function get_wikis_by_courses_returns() { return new external_single_structure( array( 'wikis' => new external_multiple_structure( new external_single_structure( array( 'id' => new external_value(PARAM_INT, 'Wiki ID.'), 'coursemodule' => new external_value(PARAM_INT, 'Course module ID.'), 'course' => new external_value(PARAM_INT, 'Course ID.'), 'name' => new external_value(PARAM_RAW, 'Wiki name.'), 'intro' => new external_value(PARAM_RAW, 'Wiki intro.', VALUE_OPTIONAL), 'introformat' => new external_format_value('Wiki intro format.', VALUE_OPTIONAL), 'introfiles' => new external_files('Files in the introduction text', VALUE_OPTIONAL), 'timecreated' => new external_value(PARAM_INT, 'Time of creation.', VALUE_OPTIONAL), 'timemodified' => new external_value(PARAM_INT, 'Time of last modification.', VALUE_OPTIONAL), 'firstpagetitle' => new external_value(PARAM_RAW, 'First page title.', VALUE_OPTIONAL), 'wikimode' => new external_value(PARAM_TEXT, 'Wiki mode (individual, collaborative).', VALUE_OPTIONAL), 'defaultformat' => new external_value(PARAM_TEXT, 'Wiki\'s default format (html, creole, nwiki).', VALUE_OPTIONAL), 'forceformat' => new external_value(PARAM_INT, '1 if format is forced, 0 otherwise.', VALUE_OPTIONAL), 'editbegin' => new external_value(PARAM_INT, 'Edit begin.', VALUE_OPTIONAL), 'editend' => new external_value(PARAM_INT, 'Edit end.', VALUE_OPTIONAL), 'section' => new external_value(PARAM_INT, 'Course section ID.', VALUE_OPTIONAL), 'visible' => new external_value(PARAM_INT, '1 if visible, 0 otherwise.', VALUE_OPTIONAL), 'groupmode' => new external_value(PARAM_INT, 'Group mode.', VALUE_OPTIONAL), 'groupingid' => new external_value(PARAM_INT, 'Group ID.', VALUE_OPTIONAL), 'cancreatepages' => new external_value(PARAM_BOOL, 'True if user can create pages.'), ), 'Wikis' ) ), 'warnings' => new external_warnings(), ) ); }
[ "public", "static", "function", "get_wikis_by_courses_returns", "(", ")", "{", "return", "new", "external_single_structure", "(", "array", "(", "'wikis'", "=>", "new", "external_multiple_structure", "(", "new", "external_single_structure", "(", "array", "(", "'id'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'Wiki ID.'", ")", ",", "'coursemodule'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'Course module ID.'", ")", ",", "'course'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'Course ID.'", ")", ",", "'name'", "=>", "new", "external_value", "(", "PARAM_RAW", ",", "'Wiki name.'", ")", ",", "'intro'", "=>", "new", "external_value", "(", "PARAM_RAW", ",", "'Wiki intro.'", ",", "VALUE_OPTIONAL", ")", ",", "'introformat'", "=>", "new", "external_format_value", "(", "'Wiki intro format.'", ",", "VALUE_OPTIONAL", ")", ",", "'introfiles'", "=>", "new", "external_files", "(", "'Files in the introduction text'", ",", "VALUE_OPTIONAL", ")", ",", "'timecreated'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'Time of creation.'", ",", "VALUE_OPTIONAL", ")", ",", "'timemodified'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'Time of last modification.'", ",", "VALUE_OPTIONAL", ")", ",", "'firstpagetitle'", "=>", "new", "external_value", "(", "PARAM_RAW", ",", "'First page title.'", ",", "VALUE_OPTIONAL", ")", ",", "'wikimode'", "=>", "new", "external_value", "(", "PARAM_TEXT", ",", "'Wiki mode (individual, collaborative).'", ",", "VALUE_OPTIONAL", ")", ",", "'defaultformat'", "=>", "new", "external_value", "(", "PARAM_TEXT", ",", "'Wiki\\'s default format (html, creole, nwiki).'", ",", "VALUE_OPTIONAL", ")", ",", "'forceformat'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'1 if format is forced, 0 otherwise.'", ",", "VALUE_OPTIONAL", ")", ",", "'editbegin'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'Edit begin.'", ",", "VALUE_OPTIONAL", ")", ",", "'editend'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'Edit end.'", ",", "VALUE_OPTIONAL", ")", ",", "'section'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'Course section ID.'", ",", "VALUE_OPTIONAL", ")", ",", "'visible'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'1 if visible, 0 otherwise.'", ",", "VALUE_OPTIONAL", ")", ",", "'groupmode'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'Group mode.'", ",", "VALUE_OPTIONAL", ")", ",", "'groupingid'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'Group ID.'", ",", "VALUE_OPTIONAL", ")", ",", "'cancreatepages'", "=>", "new", "external_value", "(", "PARAM_BOOL", ",", "'True if user can create pages.'", ")", ",", ")", ",", "'Wikis'", ")", ")", ",", "'warnings'", "=>", "new", "external_warnings", "(", ")", ",", ")", ")", ";", "}" ]
Describes the get_wikis_by_courses return value. @return external_single_structure @since Moodle 3.1
[ "Describes", "the", "get_wikis_by_courses", "return", "value", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/wiki/classes/external.php#L142-L177
212,384
moodle/moodle
mod/wiki/classes/external.php
mod_wiki_external.view_page
public static function view_page($pageid) { $params = self::validate_parameters(self::view_page_parameters(), array( 'pageid' => $pageid )); $warnings = array(); // Get wiki page. if (!$page = wiki_get_page($params['pageid'])) { throw new moodle_exception('incorrectpageid', 'wiki'); } // Get wiki instance. if (!$wiki = wiki_get_wiki_from_pageid($params['pageid'])) { throw new moodle_exception('incorrectwikiid', 'wiki'); } // Permission validation. list($course, $cm) = get_course_and_cm_from_instance($wiki, 'wiki'); $context = context_module::instance($cm->id); self::validate_context($context); // Check if user can view this wiki. if (!$subwiki = wiki_get_subwiki($page->subwikiid)) { throw new moodle_exception('incorrectsubwikiid', 'wiki'); } if (!wiki_user_can_view($subwiki, $wiki)) { throw new moodle_exception('cannotviewpage', 'wiki'); } // Trigger page_viewed event and completion. wiki_page_view($wiki, $page, $course, $cm, $context); $result = array(); $result['status'] = true; $result['warnings'] = $warnings; return $result; }
php
public static function view_page($pageid) { $params = self::validate_parameters(self::view_page_parameters(), array( 'pageid' => $pageid )); $warnings = array(); // Get wiki page. if (!$page = wiki_get_page($params['pageid'])) { throw new moodle_exception('incorrectpageid', 'wiki'); } // Get wiki instance. if (!$wiki = wiki_get_wiki_from_pageid($params['pageid'])) { throw new moodle_exception('incorrectwikiid', 'wiki'); } // Permission validation. list($course, $cm) = get_course_and_cm_from_instance($wiki, 'wiki'); $context = context_module::instance($cm->id); self::validate_context($context); // Check if user can view this wiki. if (!$subwiki = wiki_get_subwiki($page->subwikiid)) { throw new moodle_exception('incorrectsubwikiid', 'wiki'); } if (!wiki_user_can_view($subwiki, $wiki)) { throw new moodle_exception('cannotviewpage', 'wiki'); } // Trigger page_viewed event and completion. wiki_page_view($wiki, $page, $course, $cm, $context); $result = array(); $result['status'] = true; $result['warnings'] = $warnings; return $result; }
[ "public", "static", "function", "view_page", "(", "$", "pageid", ")", "{", "$", "params", "=", "self", "::", "validate_parameters", "(", "self", "::", "view_page_parameters", "(", ")", ",", "array", "(", "'pageid'", "=>", "$", "pageid", ")", ")", ";", "$", "warnings", "=", "array", "(", ")", ";", "// Get wiki page.", "if", "(", "!", "$", "page", "=", "wiki_get_page", "(", "$", "params", "[", "'pageid'", "]", ")", ")", "{", "throw", "new", "moodle_exception", "(", "'incorrectpageid'", ",", "'wiki'", ")", ";", "}", "// Get wiki instance.", "if", "(", "!", "$", "wiki", "=", "wiki_get_wiki_from_pageid", "(", "$", "params", "[", "'pageid'", "]", ")", ")", "{", "throw", "new", "moodle_exception", "(", "'incorrectwikiid'", ",", "'wiki'", ")", ";", "}", "// Permission validation.", "list", "(", "$", "course", ",", "$", "cm", ")", "=", "get_course_and_cm_from_instance", "(", "$", "wiki", ",", "'wiki'", ")", ";", "$", "context", "=", "context_module", "::", "instance", "(", "$", "cm", "->", "id", ")", ";", "self", "::", "validate_context", "(", "$", "context", ")", ";", "// Check if user can view this wiki.", "if", "(", "!", "$", "subwiki", "=", "wiki_get_subwiki", "(", "$", "page", "->", "subwikiid", ")", ")", "{", "throw", "new", "moodle_exception", "(", "'incorrectsubwikiid'", ",", "'wiki'", ")", ";", "}", "if", "(", "!", "wiki_user_can_view", "(", "$", "subwiki", ",", "$", "wiki", ")", ")", "{", "throw", "new", "moodle_exception", "(", "'cannotviewpage'", ",", "'wiki'", ")", ";", "}", "// Trigger page_viewed event and completion.", "wiki_page_view", "(", "$", "wiki", ",", "$", "page", ",", "$", "course", ",", "$", "cm", ",", "$", "context", ")", ";", "$", "result", "=", "array", "(", ")", ";", "$", "result", "[", "'status'", "]", "=", "true", ";", "$", "result", "[", "'warnings'", "]", "=", "$", "warnings", ";", "return", "$", "result", ";", "}" ]
Trigger the page viewed event and update the module completion status. @param int $pageid The page ID. @return array of warnings and status result. @since Moodle 3.1 @throws moodle_exception if page is not valid.
[ "Trigger", "the", "page", "viewed", "event", "and", "update", "the", "module", "completion", "status", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/wiki/classes/external.php#L270-L308
212,385
moodle/moodle
mod/wiki/classes/external.php
mod_wiki_external.get_subwikis
public static function get_subwikis($wikiid) { global $USER; $warnings = array(); $params = self::validate_parameters(self::get_subwikis_parameters(), array('wikiid' => $wikiid)); // Get wiki instance. if (!$wiki = wiki_get_wiki($params['wikiid'])) { throw new moodle_exception('incorrectwikiid', 'wiki'); } // Validate context and capabilities. list($course, $cm) = get_course_and_cm_from_instance($wiki, 'wiki'); $context = context_module::instance($cm->id); self::validate_context($context); require_capability('mod/wiki:viewpage', $context); $returnedsubwikis = wiki_get_visible_subwikis($wiki, $cm, $context); foreach ($returnedsubwikis as $subwiki) { $subwiki->canedit = wiki_user_can_edit($subwiki); } $result = array(); $result['subwikis'] = $returnedsubwikis; $result['warnings'] = $warnings; return $result; }
php
public static function get_subwikis($wikiid) { global $USER; $warnings = array(); $params = self::validate_parameters(self::get_subwikis_parameters(), array('wikiid' => $wikiid)); // Get wiki instance. if (!$wiki = wiki_get_wiki($params['wikiid'])) { throw new moodle_exception('incorrectwikiid', 'wiki'); } // Validate context and capabilities. list($course, $cm) = get_course_and_cm_from_instance($wiki, 'wiki'); $context = context_module::instance($cm->id); self::validate_context($context); require_capability('mod/wiki:viewpage', $context); $returnedsubwikis = wiki_get_visible_subwikis($wiki, $cm, $context); foreach ($returnedsubwikis as $subwiki) { $subwiki->canedit = wiki_user_can_edit($subwiki); } $result = array(); $result['subwikis'] = $returnedsubwikis; $result['warnings'] = $warnings; return $result; }
[ "public", "static", "function", "get_subwikis", "(", "$", "wikiid", ")", "{", "global", "$", "USER", ";", "$", "warnings", "=", "array", "(", ")", ";", "$", "params", "=", "self", "::", "validate_parameters", "(", "self", "::", "get_subwikis_parameters", "(", ")", ",", "array", "(", "'wikiid'", "=>", "$", "wikiid", ")", ")", ";", "// Get wiki instance.", "if", "(", "!", "$", "wiki", "=", "wiki_get_wiki", "(", "$", "params", "[", "'wikiid'", "]", ")", ")", "{", "throw", "new", "moodle_exception", "(", "'incorrectwikiid'", ",", "'wiki'", ")", ";", "}", "// Validate context and capabilities.", "list", "(", "$", "course", ",", "$", "cm", ")", "=", "get_course_and_cm_from_instance", "(", "$", "wiki", ",", "'wiki'", ")", ";", "$", "context", "=", "context_module", "::", "instance", "(", "$", "cm", "->", "id", ")", ";", "self", "::", "validate_context", "(", "$", "context", ")", ";", "require_capability", "(", "'mod/wiki:viewpage'", ",", "$", "context", ")", ";", "$", "returnedsubwikis", "=", "wiki_get_visible_subwikis", "(", "$", "wiki", ",", "$", "cm", ",", "$", "context", ")", ";", "foreach", "(", "$", "returnedsubwikis", "as", "$", "subwiki", ")", "{", "$", "subwiki", "->", "canedit", "=", "wiki_user_can_edit", "(", "$", "subwiki", ")", ";", "}", "$", "result", "=", "array", "(", ")", ";", "$", "result", "[", "'subwikis'", "]", "=", "$", "returnedsubwikis", ";", "$", "result", "[", "'warnings'", "]", "=", "$", "warnings", ";", "return", "$", "result", ";", "}" ]
Returns the list of subwikis the user can see in a specific wiki. @param int $wikiid The wiki instance ID. @return array Containing a list of warnings and a list of subwikis. @since Moodle 3.1
[ "Returns", "the", "list", "of", "subwikis", "the", "user", "can", "see", "in", "a", "specific", "wiki", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/wiki/classes/external.php#L346-L373
212,386
moodle/moodle
mod/wiki/classes/external.php
mod_wiki_external.get_subwikis_returns
public static function get_subwikis_returns() { return new external_single_structure( array( 'subwikis' => new external_multiple_structure( new external_single_structure( array( 'id' => new external_value(PARAM_INT, 'Subwiki ID.'), 'wikiid' => new external_value(PARAM_INT, 'Wiki ID.'), 'groupid' => new external_value(PARAM_RAW, 'Group ID.'), 'userid' => new external_value(PARAM_INT, 'User ID.'), 'canedit' => new external_value(PARAM_BOOL, 'True if user can edit the subwiki.'), ), 'Subwikis' ) ), 'warnings' => new external_warnings(), ) ); }
php
public static function get_subwikis_returns() { return new external_single_structure( array( 'subwikis' => new external_multiple_structure( new external_single_structure( array( 'id' => new external_value(PARAM_INT, 'Subwiki ID.'), 'wikiid' => new external_value(PARAM_INT, 'Wiki ID.'), 'groupid' => new external_value(PARAM_RAW, 'Group ID.'), 'userid' => new external_value(PARAM_INT, 'User ID.'), 'canedit' => new external_value(PARAM_BOOL, 'True if user can edit the subwiki.'), ), 'Subwikis' ) ), 'warnings' => new external_warnings(), ) ); }
[ "public", "static", "function", "get_subwikis_returns", "(", ")", "{", "return", "new", "external_single_structure", "(", "array", "(", "'subwikis'", "=>", "new", "external_multiple_structure", "(", "new", "external_single_structure", "(", "array", "(", "'id'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'Subwiki ID.'", ")", ",", "'wikiid'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'Wiki ID.'", ")", ",", "'groupid'", "=>", "new", "external_value", "(", "PARAM_RAW", ",", "'Group ID.'", ")", ",", "'userid'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'User ID.'", ")", ",", "'canedit'", "=>", "new", "external_value", "(", "PARAM_BOOL", ",", "'True if user can edit the subwiki.'", ")", ",", ")", ",", "'Subwikis'", ")", ")", ",", "'warnings'", "=>", "new", "external_warnings", "(", ")", ",", ")", ")", ";", "}" ]
Describes the get_subwikis return value. @return external_single_structure @since Moodle 3.1
[ "Describes", "the", "get_subwikis", "return", "value", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/wiki/classes/external.php#L381-L398
212,387
moodle/moodle
mod/wiki/classes/external.php
mod_wiki_external.get_subwiki_pages_parameters
public static function get_subwiki_pages_parameters() { return new external_function_parameters ( array( 'wikiid' => new external_value(PARAM_INT, 'Wiki instance ID.'), 'groupid' => new external_value(PARAM_INT, 'Subwiki\'s group ID, -1 means current group. It will be ignored' . ' if the wiki doesn\'t use groups.', VALUE_DEFAULT, -1), 'userid' => new external_value(PARAM_INT, 'Subwiki\'s user ID, 0 means current user. It will be ignored' .' in collaborative wikis.', VALUE_DEFAULT, 0), 'options' => new external_single_structure( array( 'sortby' => new external_value(PARAM_ALPHA, 'Field to sort by (id, title, ...).', VALUE_DEFAULT, 'title'), 'sortdirection' => new external_value(PARAM_ALPHA, 'Sort direction: ASC or DESC.', VALUE_DEFAULT, 'ASC'), 'includecontent' => new external_value(PARAM_INT, 'Include each page contents or just the contents size.', VALUE_DEFAULT, 1), ), 'Options', VALUE_DEFAULT, array()), ) ); }
php
public static function get_subwiki_pages_parameters() { return new external_function_parameters ( array( 'wikiid' => new external_value(PARAM_INT, 'Wiki instance ID.'), 'groupid' => new external_value(PARAM_INT, 'Subwiki\'s group ID, -1 means current group. It will be ignored' . ' if the wiki doesn\'t use groups.', VALUE_DEFAULT, -1), 'userid' => new external_value(PARAM_INT, 'Subwiki\'s user ID, 0 means current user. It will be ignored' .' in collaborative wikis.', VALUE_DEFAULT, 0), 'options' => new external_single_structure( array( 'sortby' => new external_value(PARAM_ALPHA, 'Field to sort by (id, title, ...).', VALUE_DEFAULT, 'title'), 'sortdirection' => new external_value(PARAM_ALPHA, 'Sort direction: ASC or DESC.', VALUE_DEFAULT, 'ASC'), 'includecontent' => new external_value(PARAM_INT, 'Include each page contents or just the contents size.', VALUE_DEFAULT, 1), ), 'Options', VALUE_DEFAULT, array()), ) ); }
[ "public", "static", "function", "get_subwiki_pages_parameters", "(", ")", "{", "return", "new", "external_function_parameters", "(", "array", "(", "'wikiid'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'Wiki instance ID.'", ")", ",", "'groupid'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'Subwiki\\'s group ID, -1 means current group. It will be ignored'", ".", "' if the wiki doesn\\'t use groups.'", ",", "VALUE_DEFAULT", ",", "-", "1", ")", ",", "'userid'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'Subwiki\\'s user ID, 0 means current user. It will be ignored'", ".", "' in collaborative wikis.'", ",", "VALUE_DEFAULT", ",", "0", ")", ",", "'options'", "=>", "new", "external_single_structure", "(", "array", "(", "'sortby'", "=>", "new", "external_value", "(", "PARAM_ALPHA", ",", "'Field to sort by (id, title, ...).'", ",", "VALUE_DEFAULT", ",", "'title'", ")", ",", "'sortdirection'", "=>", "new", "external_value", "(", "PARAM_ALPHA", ",", "'Sort direction: ASC or DESC.'", ",", "VALUE_DEFAULT", ",", "'ASC'", ")", ",", "'includecontent'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'Include each page contents or just the contents size.'", ",", "VALUE_DEFAULT", ",", "1", ")", ",", ")", ",", "'Options'", ",", "VALUE_DEFAULT", ",", "array", "(", ")", ")", ",", ")", ")", ";", "}" ]
Describes the parameters for get_subwiki_pages. @return external_function_parameters @since Moodle 3.1
[ "Describes", "the", "parameters", "for", "get_subwiki_pages", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/wiki/classes/external.php#L406-L425
212,388
moodle/moodle
mod/wiki/classes/external.php
mod_wiki_external.get_subwiki_pages_returns
public static function get_subwiki_pages_returns() { return new external_single_structure( array( 'pages' => new external_multiple_structure( new external_single_structure( array( 'id' => new external_value(PARAM_INT, 'Page ID.'), 'subwikiid' => new external_value(PARAM_INT, 'Page\'s subwiki ID.'), 'title' => new external_value(PARAM_RAW, 'Page title.'), 'timecreated' => new external_value(PARAM_INT, 'Time of creation.'), 'timemodified' => new external_value(PARAM_INT, 'Time of last modification.'), 'timerendered' => new external_value(PARAM_INT, 'Time of last renderization.'), 'userid' => new external_value(PARAM_INT, 'ID of the user that last modified the page.'), 'pageviews' => new external_value(PARAM_INT, 'Number of times the page has been viewed.'), 'readonly' => new external_value(PARAM_INT, '1 if readonly, 0 otherwise.'), 'caneditpage' => new external_value(PARAM_BOOL, 'True if user can edit the page.'), 'firstpage' => new external_value(PARAM_BOOL, 'True if it\'s the first page.'), 'cachedcontent' => new external_value(PARAM_RAW, 'Page contents.', VALUE_OPTIONAL), 'contentformat' => new external_format_value('cachedcontent', VALUE_OPTIONAL), 'contentsize' => new external_value(PARAM_INT, 'Size of page contents in bytes (doesn\'t include'. ' size of attached files).', VALUE_OPTIONAL), 'tags' => new external_multiple_structure( \core_tag\external\tag_item_exporter::get_read_structure(), 'Tags', VALUE_OPTIONAL ), ), 'Pages' ) ), 'warnings' => new external_warnings(), ) ); }
php
public static function get_subwiki_pages_returns() { return new external_single_structure( array( 'pages' => new external_multiple_structure( new external_single_structure( array( 'id' => new external_value(PARAM_INT, 'Page ID.'), 'subwikiid' => new external_value(PARAM_INT, 'Page\'s subwiki ID.'), 'title' => new external_value(PARAM_RAW, 'Page title.'), 'timecreated' => new external_value(PARAM_INT, 'Time of creation.'), 'timemodified' => new external_value(PARAM_INT, 'Time of last modification.'), 'timerendered' => new external_value(PARAM_INT, 'Time of last renderization.'), 'userid' => new external_value(PARAM_INT, 'ID of the user that last modified the page.'), 'pageviews' => new external_value(PARAM_INT, 'Number of times the page has been viewed.'), 'readonly' => new external_value(PARAM_INT, '1 if readonly, 0 otherwise.'), 'caneditpage' => new external_value(PARAM_BOOL, 'True if user can edit the page.'), 'firstpage' => new external_value(PARAM_BOOL, 'True if it\'s the first page.'), 'cachedcontent' => new external_value(PARAM_RAW, 'Page contents.', VALUE_OPTIONAL), 'contentformat' => new external_format_value('cachedcontent', VALUE_OPTIONAL), 'contentsize' => new external_value(PARAM_INT, 'Size of page contents in bytes (doesn\'t include'. ' size of attached files).', VALUE_OPTIONAL), 'tags' => new external_multiple_structure( \core_tag\external\tag_item_exporter::get_read_structure(), 'Tags', VALUE_OPTIONAL ), ), 'Pages' ) ), 'warnings' => new external_warnings(), ) ); }
[ "public", "static", "function", "get_subwiki_pages_returns", "(", ")", "{", "return", "new", "external_single_structure", "(", "array", "(", "'pages'", "=>", "new", "external_multiple_structure", "(", "new", "external_single_structure", "(", "array", "(", "'id'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'Page ID.'", ")", ",", "'subwikiid'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'Page\\'s subwiki ID.'", ")", ",", "'title'", "=>", "new", "external_value", "(", "PARAM_RAW", ",", "'Page title.'", ")", ",", "'timecreated'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'Time of creation.'", ")", ",", "'timemodified'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'Time of last modification.'", ")", ",", "'timerendered'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'Time of last renderization.'", ")", ",", "'userid'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'ID of the user that last modified the page.'", ")", ",", "'pageviews'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'Number of times the page has been viewed.'", ")", ",", "'readonly'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'1 if readonly, 0 otherwise.'", ")", ",", "'caneditpage'", "=>", "new", "external_value", "(", "PARAM_BOOL", ",", "'True if user can edit the page.'", ")", ",", "'firstpage'", "=>", "new", "external_value", "(", "PARAM_BOOL", ",", "'True if it\\'s the first page.'", ")", ",", "'cachedcontent'", "=>", "new", "external_value", "(", "PARAM_RAW", ",", "'Page contents.'", ",", "VALUE_OPTIONAL", ")", ",", "'contentformat'", "=>", "new", "external_format_value", "(", "'cachedcontent'", ",", "VALUE_OPTIONAL", ")", ",", "'contentsize'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'Size of page contents in bytes (doesn\\'t include'", ".", "' size of attached files).'", ",", "VALUE_OPTIONAL", ")", ",", "'tags'", "=>", "new", "external_multiple_structure", "(", "\\", "core_tag", "\\", "external", "\\", "tag_item_exporter", "::", "get_read_structure", "(", ")", ",", "'Tags'", ",", "VALUE_OPTIONAL", ")", ",", ")", ",", "'Pages'", ")", ")", ",", "'warnings'", "=>", "new", "external_warnings", "(", ")", ",", ")", ")", ";", "}" ]
Describes the get_subwiki_pages return value. @return external_single_structure @since Moodle 3.1
[ "Describes", "the", "get_subwiki_pages", "return", "value", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/wiki/classes/external.php#L537-L568
212,389
moodle/moodle
mod/wiki/classes/external.php
mod_wiki_external.get_page_contents
public static function get_page_contents($pageid) { $params = self::validate_parameters(self::get_page_contents_parameters(), array( 'pageid' => $pageid ) ); $warnings = array(); // Get wiki page. if (!$page = wiki_get_page($params['pageid'])) { throw new moodle_exception('incorrectpageid', 'wiki'); } // Get wiki instance. if (!$wiki = wiki_get_wiki_from_pageid($params['pageid'])) { throw new moodle_exception('incorrectwikiid', 'wiki'); } // Permission validation. $cm = get_coursemodule_from_instance('wiki', $wiki->id, $wiki->course); $context = context_module::instance($cm->id); self::validate_context($context); // Check if user can view this wiki. if (!$subwiki = wiki_get_subwiki($page->subwikiid)) { throw new moodle_exception('incorrectsubwikiid', 'wiki'); } if (!wiki_user_can_view($subwiki, $wiki)) { throw new moodle_exception('cannotviewpage', 'wiki'); } $returnedpage = array(); $returnedpage['id'] = $page->id; $returnedpage['wikiid'] = $wiki->id; $returnedpage['subwikiid'] = $page->subwikiid; $returnedpage['groupid'] = $subwiki->groupid; $returnedpage['userid'] = $subwiki->userid; $returnedpage['title'] = $page->title; $returnedpage['tags'] = \core_tag\external\util::get_item_tags('mod_wiki', 'wiki_pages', $page->id); // Refresh page cached content if needed. if ($page->timerendered + WIKI_REFRESH_CACHE_TIME < time()) { if ($content = wiki_refresh_cachedcontent($page)) { $page = $content['page']; } } list($returnedpage['cachedcontent'], $returnedpage['contentformat']) = external_format_text( $page->cachedcontent, FORMAT_HTML, $context->id, 'mod_wiki', 'attachments', $subwiki->id); $returnedpage['caneditpage'] = wiki_user_can_edit($subwiki); // Get page version. $version = wiki_get_current_version($page->id); if (!empty($version)) { $returnedpage['version'] = $version->version; } $result = array(); $result['page'] = $returnedpage; $result['warnings'] = $warnings; return $result; }
php
public static function get_page_contents($pageid) { $params = self::validate_parameters(self::get_page_contents_parameters(), array( 'pageid' => $pageid ) ); $warnings = array(); // Get wiki page. if (!$page = wiki_get_page($params['pageid'])) { throw new moodle_exception('incorrectpageid', 'wiki'); } // Get wiki instance. if (!$wiki = wiki_get_wiki_from_pageid($params['pageid'])) { throw new moodle_exception('incorrectwikiid', 'wiki'); } // Permission validation. $cm = get_coursemodule_from_instance('wiki', $wiki->id, $wiki->course); $context = context_module::instance($cm->id); self::validate_context($context); // Check if user can view this wiki. if (!$subwiki = wiki_get_subwiki($page->subwikiid)) { throw new moodle_exception('incorrectsubwikiid', 'wiki'); } if (!wiki_user_can_view($subwiki, $wiki)) { throw new moodle_exception('cannotviewpage', 'wiki'); } $returnedpage = array(); $returnedpage['id'] = $page->id; $returnedpage['wikiid'] = $wiki->id; $returnedpage['subwikiid'] = $page->subwikiid; $returnedpage['groupid'] = $subwiki->groupid; $returnedpage['userid'] = $subwiki->userid; $returnedpage['title'] = $page->title; $returnedpage['tags'] = \core_tag\external\util::get_item_tags('mod_wiki', 'wiki_pages', $page->id); // Refresh page cached content if needed. if ($page->timerendered + WIKI_REFRESH_CACHE_TIME < time()) { if ($content = wiki_refresh_cachedcontent($page)) { $page = $content['page']; } } list($returnedpage['cachedcontent'], $returnedpage['contentformat']) = external_format_text( $page->cachedcontent, FORMAT_HTML, $context->id, 'mod_wiki', 'attachments', $subwiki->id); $returnedpage['caneditpage'] = wiki_user_can_edit($subwiki); // Get page version. $version = wiki_get_current_version($page->id); if (!empty($version)) { $returnedpage['version'] = $version->version; } $result = array(); $result['page'] = $returnedpage; $result['warnings'] = $warnings; return $result; }
[ "public", "static", "function", "get_page_contents", "(", "$", "pageid", ")", "{", "$", "params", "=", "self", "::", "validate_parameters", "(", "self", "::", "get_page_contents_parameters", "(", ")", ",", "array", "(", "'pageid'", "=>", "$", "pageid", ")", ")", ";", "$", "warnings", "=", "array", "(", ")", ";", "// Get wiki page.", "if", "(", "!", "$", "page", "=", "wiki_get_page", "(", "$", "params", "[", "'pageid'", "]", ")", ")", "{", "throw", "new", "moodle_exception", "(", "'incorrectpageid'", ",", "'wiki'", ")", ";", "}", "// Get wiki instance.", "if", "(", "!", "$", "wiki", "=", "wiki_get_wiki_from_pageid", "(", "$", "params", "[", "'pageid'", "]", ")", ")", "{", "throw", "new", "moodle_exception", "(", "'incorrectwikiid'", ",", "'wiki'", ")", ";", "}", "// Permission validation.", "$", "cm", "=", "get_coursemodule_from_instance", "(", "'wiki'", ",", "$", "wiki", "->", "id", ",", "$", "wiki", "->", "course", ")", ";", "$", "context", "=", "context_module", "::", "instance", "(", "$", "cm", "->", "id", ")", ";", "self", "::", "validate_context", "(", "$", "context", ")", ";", "// Check if user can view this wiki.", "if", "(", "!", "$", "subwiki", "=", "wiki_get_subwiki", "(", "$", "page", "->", "subwikiid", ")", ")", "{", "throw", "new", "moodle_exception", "(", "'incorrectsubwikiid'", ",", "'wiki'", ")", ";", "}", "if", "(", "!", "wiki_user_can_view", "(", "$", "subwiki", ",", "$", "wiki", ")", ")", "{", "throw", "new", "moodle_exception", "(", "'cannotviewpage'", ",", "'wiki'", ")", ";", "}", "$", "returnedpage", "=", "array", "(", ")", ";", "$", "returnedpage", "[", "'id'", "]", "=", "$", "page", "->", "id", ";", "$", "returnedpage", "[", "'wikiid'", "]", "=", "$", "wiki", "->", "id", ";", "$", "returnedpage", "[", "'subwikiid'", "]", "=", "$", "page", "->", "subwikiid", ";", "$", "returnedpage", "[", "'groupid'", "]", "=", "$", "subwiki", "->", "groupid", ";", "$", "returnedpage", "[", "'userid'", "]", "=", "$", "subwiki", "->", "userid", ";", "$", "returnedpage", "[", "'title'", "]", "=", "$", "page", "->", "title", ";", "$", "returnedpage", "[", "'tags'", "]", "=", "\\", "core_tag", "\\", "external", "\\", "util", "::", "get_item_tags", "(", "'mod_wiki'", ",", "'wiki_pages'", ",", "$", "page", "->", "id", ")", ";", "// Refresh page cached content if needed.", "if", "(", "$", "page", "->", "timerendered", "+", "WIKI_REFRESH_CACHE_TIME", "<", "time", "(", ")", ")", "{", "if", "(", "$", "content", "=", "wiki_refresh_cachedcontent", "(", "$", "page", ")", ")", "{", "$", "page", "=", "$", "content", "[", "'page'", "]", ";", "}", "}", "list", "(", "$", "returnedpage", "[", "'cachedcontent'", "]", ",", "$", "returnedpage", "[", "'contentformat'", "]", ")", "=", "external_format_text", "(", "$", "page", "->", "cachedcontent", ",", "FORMAT_HTML", ",", "$", "context", "->", "id", ",", "'mod_wiki'", ",", "'attachments'", ",", "$", "subwiki", "->", "id", ")", ";", "$", "returnedpage", "[", "'caneditpage'", "]", "=", "wiki_user_can_edit", "(", "$", "subwiki", ")", ";", "// Get page version.", "$", "version", "=", "wiki_get_current_version", "(", "$", "page", "->", "id", ")", ";", "if", "(", "!", "empty", "(", "$", "version", ")", ")", "{", "$", "returnedpage", "[", "'version'", "]", "=", "$", "version", "->", "version", ";", "}", "$", "result", "=", "array", "(", ")", ";", "$", "result", "[", "'page'", "]", "=", "$", "returnedpage", ";", "$", "result", "[", "'warnings'", "]", "=", "$", "warnings", ";", "return", "$", "result", ";", "}" ]
Get a page contents. @param int $pageid The page ID. @return array of warnings and page data. @since Moodle 3.1
[ "Get", "a", "page", "contents", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/wiki/classes/external.php#L591-L653
212,390
moodle/moodle
mod/wiki/classes/external.php
mod_wiki_external.get_subwiki_files_parameters
public static function get_subwiki_files_parameters() { return new external_function_parameters ( array( 'wikiid' => new external_value(PARAM_INT, 'Wiki instance ID.'), 'groupid' => new external_value(PARAM_INT, 'Subwiki\'s group ID, -1 means current group. It will be ignored' . ' if the wiki doesn\'t use groups.', VALUE_DEFAULT, -1), 'userid' => new external_value(PARAM_INT, 'Subwiki\'s user ID, 0 means current user. It will be ignored' .' in collaborative wikis.', VALUE_DEFAULT, 0) ) ); }
php
public static function get_subwiki_files_parameters() { return new external_function_parameters ( array( 'wikiid' => new external_value(PARAM_INT, 'Wiki instance ID.'), 'groupid' => new external_value(PARAM_INT, 'Subwiki\'s group ID, -1 means current group. It will be ignored' . ' if the wiki doesn\'t use groups.', VALUE_DEFAULT, -1), 'userid' => new external_value(PARAM_INT, 'Subwiki\'s user ID, 0 means current user. It will be ignored' .' in collaborative wikis.', VALUE_DEFAULT, 0) ) ); }
[ "public", "static", "function", "get_subwiki_files_parameters", "(", ")", "{", "return", "new", "external_function_parameters", "(", "array", "(", "'wikiid'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'Wiki instance ID.'", ")", ",", "'groupid'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'Subwiki\\'s group ID, -1 means current group. It will be ignored'", ".", "' if the wiki doesn\\'t use groups.'", ",", "VALUE_DEFAULT", ",", "-", "1", ")", ",", "'userid'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'Subwiki\\'s user ID, 0 means current user. It will be ignored'", ".", "' in collaborative wikis.'", ",", "VALUE_DEFAULT", ",", "0", ")", ")", ")", ";", "}" ]
Describes the parameters for get_subwiki_files. @return external_function_parameters @since Moodle 3.1
[ "Describes", "the", "parameters", "for", "get_subwiki_files", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/wiki/classes/external.php#L692-L702
212,391
moodle/moodle
mod/wiki/classes/external.php
mod_wiki_external.get_subwiki_files
public static function get_subwiki_files($wikiid, $groupid = -1, $userid = 0) { $returnedfiles = array(); $warnings = array(); $params = self::validate_parameters(self::get_subwiki_files_parameters(), array( 'wikiid' => $wikiid, 'groupid' => $groupid, 'userid' => $userid ) ); // Get wiki instance. if (!$wiki = wiki_get_wiki($params['wikiid'])) { throw new moodle_exception('incorrectwikiid', 'wiki'); } list($course, $cm) = get_course_and_cm_from_instance($wiki, 'wiki'); $context = context_module::instance($cm->id); self::validate_context($context); // Determine groupid and userid to use. list($groupid, $userid) = self::determine_group_and_user($cm, $wiki, $params['groupid'], $params['userid']); // Get subwiki and validate it. $subwiki = wiki_get_subwiki_by_group_and_user_with_validation($wiki, $groupid, $userid); // Get subwiki based on group and user. if ($subwiki === false) { throw new moodle_exception('cannotviewfiles', 'wiki'); } else if ($subwiki->id != -1) { // The subwiki exists, let's get the files. $returnedfiles = external_util::get_area_files($context->id, 'mod_wiki', 'attachments', $subwiki->id); } $result = array(); $result['files'] = $returnedfiles; $result['warnings'] = $warnings; return $result; }
php
public static function get_subwiki_files($wikiid, $groupid = -1, $userid = 0) { $returnedfiles = array(); $warnings = array(); $params = self::validate_parameters(self::get_subwiki_files_parameters(), array( 'wikiid' => $wikiid, 'groupid' => $groupid, 'userid' => $userid ) ); // Get wiki instance. if (!$wiki = wiki_get_wiki($params['wikiid'])) { throw new moodle_exception('incorrectwikiid', 'wiki'); } list($course, $cm) = get_course_and_cm_from_instance($wiki, 'wiki'); $context = context_module::instance($cm->id); self::validate_context($context); // Determine groupid and userid to use. list($groupid, $userid) = self::determine_group_and_user($cm, $wiki, $params['groupid'], $params['userid']); // Get subwiki and validate it. $subwiki = wiki_get_subwiki_by_group_and_user_with_validation($wiki, $groupid, $userid); // Get subwiki based on group and user. if ($subwiki === false) { throw new moodle_exception('cannotviewfiles', 'wiki'); } else if ($subwiki->id != -1) { // The subwiki exists, let's get the files. $returnedfiles = external_util::get_area_files($context->id, 'mod_wiki', 'attachments', $subwiki->id); } $result = array(); $result['files'] = $returnedfiles; $result['warnings'] = $warnings; return $result; }
[ "public", "static", "function", "get_subwiki_files", "(", "$", "wikiid", ",", "$", "groupid", "=", "-", "1", ",", "$", "userid", "=", "0", ")", "{", "$", "returnedfiles", "=", "array", "(", ")", ";", "$", "warnings", "=", "array", "(", ")", ";", "$", "params", "=", "self", "::", "validate_parameters", "(", "self", "::", "get_subwiki_files_parameters", "(", ")", ",", "array", "(", "'wikiid'", "=>", "$", "wikiid", ",", "'groupid'", "=>", "$", "groupid", ",", "'userid'", "=>", "$", "userid", ")", ")", ";", "// Get wiki instance.", "if", "(", "!", "$", "wiki", "=", "wiki_get_wiki", "(", "$", "params", "[", "'wikiid'", "]", ")", ")", "{", "throw", "new", "moodle_exception", "(", "'incorrectwikiid'", ",", "'wiki'", ")", ";", "}", "list", "(", "$", "course", ",", "$", "cm", ")", "=", "get_course_and_cm_from_instance", "(", "$", "wiki", ",", "'wiki'", ")", ";", "$", "context", "=", "context_module", "::", "instance", "(", "$", "cm", "->", "id", ")", ";", "self", "::", "validate_context", "(", "$", "context", ")", ";", "// Determine groupid and userid to use.", "list", "(", "$", "groupid", ",", "$", "userid", ")", "=", "self", "::", "determine_group_and_user", "(", "$", "cm", ",", "$", "wiki", ",", "$", "params", "[", "'groupid'", "]", ",", "$", "params", "[", "'userid'", "]", ")", ";", "// Get subwiki and validate it.", "$", "subwiki", "=", "wiki_get_subwiki_by_group_and_user_with_validation", "(", "$", "wiki", ",", "$", "groupid", ",", "$", "userid", ")", ";", "// Get subwiki based on group and user.", "if", "(", "$", "subwiki", "===", "false", ")", "{", "throw", "new", "moodle_exception", "(", "'cannotviewfiles'", ",", "'wiki'", ")", ";", "}", "else", "if", "(", "$", "subwiki", "->", "id", "!=", "-", "1", ")", "{", "// The subwiki exists, let's get the files.", "$", "returnedfiles", "=", "external_util", "::", "get_area_files", "(", "$", "context", "->", "id", ",", "'mod_wiki'", ",", "'attachments'", ",", "$", "subwiki", "->", "id", ")", ";", "}", "$", "result", "=", "array", "(", ")", ";", "$", "result", "[", "'files'", "]", "=", "$", "returnedfiles", ";", "$", "result", "[", "'warnings'", "]", "=", "$", "warnings", ";", "return", "$", "result", ";", "}" ]
Returns the list of files from a specific subwiki. @param int $wikiid The wiki instance ID. @param int $groupid The group ID. If not defined, use current group. @param int $userid The user ID. If not defined, use current user. @return array Containing a list of warnings and a list of files. @since Moodle 3.1 @throws moodle_exception
[ "Returns", "the", "list", "of", "files", "from", "a", "specific", "subwiki", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/wiki/classes/external.php#L714-L753
212,392
moodle/moodle
mod/wiki/classes/external.php
mod_wiki_external.determine_group_and_user
protected static function determine_group_and_user($cm, $wiki, $groupid = -1, $userid = 0) { global $USER; $currentgroup = groups_get_activity_group($cm); if ($currentgroup === false) { // Activity doesn't use groups. $groupid = 0; } else if ($groupid == -1) { // Use current group. $groupid = !empty($currentgroup) ? $currentgroup : 0; } // Determine user. if ($wiki->wikimode == 'collaborative') { // Collaborative wikis don't use userid in subwikis. $userid = 0; } else if (empty($userid)) { // Use current user. $userid = $USER->id; } return array($groupid, $userid); }
php
protected static function determine_group_and_user($cm, $wiki, $groupid = -1, $userid = 0) { global $USER; $currentgroup = groups_get_activity_group($cm); if ($currentgroup === false) { // Activity doesn't use groups. $groupid = 0; } else if ($groupid == -1) { // Use current group. $groupid = !empty($currentgroup) ? $currentgroup : 0; } // Determine user. if ($wiki->wikimode == 'collaborative') { // Collaborative wikis don't use userid in subwikis. $userid = 0; } else if (empty($userid)) { // Use current user. $userid = $USER->id; } return array($groupid, $userid); }
[ "protected", "static", "function", "determine_group_and_user", "(", "$", "cm", ",", "$", "wiki", ",", "$", "groupid", "=", "-", "1", ",", "$", "userid", "=", "0", ")", "{", "global", "$", "USER", ";", "$", "currentgroup", "=", "groups_get_activity_group", "(", "$", "cm", ")", ";", "if", "(", "$", "currentgroup", "===", "false", ")", "{", "// Activity doesn't use groups.", "$", "groupid", "=", "0", ";", "}", "else", "if", "(", "$", "groupid", "==", "-", "1", ")", "{", "// Use current group.", "$", "groupid", "=", "!", "empty", "(", "$", "currentgroup", ")", "?", "$", "currentgroup", ":", "0", ";", "}", "// Determine user.", "if", "(", "$", "wiki", "->", "wikimode", "==", "'collaborative'", ")", "{", "// Collaborative wikis don't use userid in subwikis.", "$", "userid", "=", "0", ";", "}", "else", "if", "(", "empty", "(", "$", "userid", ")", ")", "{", "// Use current user.", "$", "userid", "=", "$", "USER", "->", "id", ";", "}", "return", "array", "(", "$", "groupid", ",", "$", "userid", ")", ";", "}" ]
Utility function for determining the groupid and userid to use. @param stdClass $cm The course module. @param stdClass $wiki The wiki. @param int $groupid Group ID. If not defined, use current group. @param int $userid User ID. If not defined, use current user. @return array Array containing the courseid and userid. @since Moodle 3.1
[ "Utility", "function", "for", "determining", "the", "groupid", "and", "userid", "to", "use", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/wiki/classes/external.php#L781-L803
212,393
moodle/moodle
mod/wiki/classes/external.php
mod_wiki_external.get_page_for_editing_parameters
public static function get_page_for_editing_parameters() { return new external_function_parameters ( array( 'pageid' => new external_value(PARAM_INT, 'Page ID to edit.'), 'section' => new external_value(PARAM_RAW, 'Section page title.', VALUE_DEFAULT, null), 'lockonly' => new external_value(PARAM_BOOL, 'Just renew lock and not return content.', VALUE_DEFAULT, false) ) ); }
php
public static function get_page_for_editing_parameters() { return new external_function_parameters ( array( 'pageid' => new external_value(PARAM_INT, 'Page ID to edit.'), 'section' => new external_value(PARAM_RAW, 'Section page title.', VALUE_DEFAULT, null), 'lockonly' => new external_value(PARAM_BOOL, 'Just renew lock and not return content.', VALUE_DEFAULT, false) ) ); }
[ "public", "static", "function", "get_page_for_editing_parameters", "(", ")", "{", "return", "new", "external_function_parameters", "(", "array", "(", "'pageid'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'Page ID to edit.'", ")", ",", "'section'", "=>", "new", "external_value", "(", "PARAM_RAW", ",", "'Section page title.'", ",", "VALUE_DEFAULT", ",", "null", ")", ",", "'lockonly'", "=>", "new", "external_value", "(", "PARAM_BOOL", ",", "'Just renew lock and not return content.'", ",", "VALUE_DEFAULT", ",", "false", ")", ")", ")", ";", "}" ]
Describes the parameters for get_page_for_editing. @return external_function_parameters @since Moodle 3.1
[ "Describes", "the", "parameters", "for", "get_page_for_editing", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/wiki/classes/external.php#L811-L819
212,394
moodle/moodle
mod/wiki/classes/external.php
mod_wiki_external.get_page_for_editing
public static function get_page_for_editing($pageid, $section = null, $lockonly = false) { global $USER; $params = self::validate_parameters(self::get_page_for_editing_parameters(), array( 'pageid' => $pageid, 'section' => $section, 'lockonly' => $lockonly ) ); $warnings = array(); // Get wiki page. if (!$page = wiki_get_page($params['pageid'])) { throw new moodle_exception('incorrectpageid', 'wiki'); } // Get wiki instance. if (!$wiki = wiki_get_wiki_from_pageid($params['pageid'])) { throw new moodle_exception('incorrectwikiid', 'wiki'); } // Get subwiki instance. if (!$subwiki = wiki_get_subwiki($page->subwikiid)) { throw new moodle_exception('incorrectsubwikiid', 'wiki'); } // Permission validation. $cm = get_coursemodule_from_instance('wiki', $wiki->id, $wiki->course); $context = context_module::instance($cm->id); self::validate_context($context); if (!wiki_user_can_edit($subwiki)) { throw new moodle_exception('cannoteditpage', 'wiki'); } if (!wiki_set_lock($params['pageid'], $USER->id, $params['section'], true)) { throw new moodle_exception('pageislocked', 'wiki'); } $version = wiki_get_current_version($page->id); if (empty($version)) { throw new moodle_exception('versionerror', 'wiki'); } $pagesection = array(); $pagesection['version'] = $version->version; // Content requested to be returned. if (!$lockonly) { if (!is_null($params['section'])) { $content = wiki_parser_proxy::get_section($version->content, $version->contentformat, $params['section']); } else { $content = $version->content; } $pagesection['content'] = $content; $pagesection['contentformat'] = $version->contentformat; } $result = array(); $result['pagesection'] = $pagesection; $result['warnings'] = $warnings; return $result; }
php
public static function get_page_for_editing($pageid, $section = null, $lockonly = false) { global $USER; $params = self::validate_parameters(self::get_page_for_editing_parameters(), array( 'pageid' => $pageid, 'section' => $section, 'lockonly' => $lockonly ) ); $warnings = array(); // Get wiki page. if (!$page = wiki_get_page($params['pageid'])) { throw new moodle_exception('incorrectpageid', 'wiki'); } // Get wiki instance. if (!$wiki = wiki_get_wiki_from_pageid($params['pageid'])) { throw new moodle_exception('incorrectwikiid', 'wiki'); } // Get subwiki instance. if (!$subwiki = wiki_get_subwiki($page->subwikiid)) { throw new moodle_exception('incorrectsubwikiid', 'wiki'); } // Permission validation. $cm = get_coursemodule_from_instance('wiki', $wiki->id, $wiki->course); $context = context_module::instance($cm->id); self::validate_context($context); if (!wiki_user_can_edit($subwiki)) { throw new moodle_exception('cannoteditpage', 'wiki'); } if (!wiki_set_lock($params['pageid'], $USER->id, $params['section'], true)) { throw new moodle_exception('pageislocked', 'wiki'); } $version = wiki_get_current_version($page->id); if (empty($version)) { throw new moodle_exception('versionerror', 'wiki'); } $pagesection = array(); $pagesection['version'] = $version->version; // Content requested to be returned. if (!$lockonly) { if (!is_null($params['section'])) { $content = wiki_parser_proxy::get_section($version->content, $version->contentformat, $params['section']); } else { $content = $version->content; } $pagesection['content'] = $content; $pagesection['contentformat'] = $version->contentformat; } $result = array(); $result['pagesection'] = $pagesection; $result['warnings'] = $warnings; return $result; }
[ "public", "static", "function", "get_page_for_editing", "(", "$", "pageid", ",", "$", "section", "=", "null", ",", "$", "lockonly", "=", "false", ")", "{", "global", "$", "USER", ";", "$", "params", "=", "self", "::", "validate_parameters", "(", "self", "::", "get_page_for_editing_parameters", "(", ")", ",", "array", "(", "'pageid'", "=>", "$", "pageid", ",", "'section'", "=>", "$", "section", ",", "'lockonly'", "=>", "$", "lockonly", ")", ")", ";", "$", "warnings", "=", "array", "(", ")", ";", "// Get wiki page.", "if", "(", "!", "$", "page", "=", "wiki_get_page", "(", "$", "params", "[", "'pageid'", "]", ")", ")", "{", "throw", "new", "moodle_exception", "(", "'incorrectpageid'", ",", "'wiki'", ")", ";", "}", "// Get wiki instance.", "if", "(", "!", "$", "wiki", "=", "wiki_get_wiki_from_pageid", "(", "$", "params", "[", "'pageid'", "]", ")", ")", "{", "throw", "new", "moodle_exception", "(", "'incorrectwikiid'", ",", "'wiki'", ")", ";", "}", "// Get subwiki instance.", "if", "(", "!", "$", "subwiki", "=", "wiki_get_subwiki", "(", "$", "page", "->", "subwikiid", ")", ")", "{", "throw", "new", "moodle_exception", "(", "'incorrectsubwikiid'", ",", "'wiki'", ")", ";", "}", "// Permission validation.", "$", "cm", "=", "get_coursemodule_from_instance", "(", "'wiki'", ",", "$", "wiki", "->", "id", ",", "$", "wiki", "->", "course", ")", ";", "$", "context", "=", "context_module", "::", "instance", "(", "$", "cm", "->", "id", ")", ";", "self", "::", "validate_context", "(", "$", "context", ")", ";", "if", "(", "!", "wiki_user_can_edit", "(", "$", "subwiki", ")", ")", "{", "throw", "new", "moodle_exception", "(", "'cannoteditpage'", ",", "'wiki'", ")", ";", "}", "if", "(", "!", "wiki_set_lock", "(", "$", "params", "[", "'pageid'", "]", ",", "$", "USER", "->", "id", ",", "$", "params", "[", "'section'", "]", ",", "true", ")", ")", "{", "throw", "new", "moodle_exception", "(", "'pageislocked'", ",", "'wiki'", ")", ";", "}", "$", "version", "=", "wiki_get_current_version", "(", "$", "page", "->", "id", ")", ";", "if", "(", "empty", "(", "$", "version", ")", ")", "{", "throw", "new", "moodle_exception", "(", "'versionerror'", ",", "'wiki'", ")", ";", "}", "$", "pagesection", "=", "array", "(", ")", ";", "$", "pagesection", "[", "'version'", "]", "=", "$", "version", "->", "version", ";", "// Content requested to be returned.", "if", "(", "!", "$", "lockonly", ")", "{", "if", "(", "!", "is_null", "(", "$", "params", "[", "'section'", "]", ")", ")", "{", "$", "content", "=", "wiki_parser_proxy", "::", "get_section", "(", "$", "version", "->", "content", ",", "$", "version", "->", "contentformat", ",", "$", "params", "[", "'section'", "]", ")", ";", "}", "else", "{", "$", "content", "=", "$", "version", "->", "content", ";", "}", "$", "pagesection", "[", "'content'", "]", "=", "$", "content", ";", "$", "pagesection", "[", "'contentformat'", "]", "=", "$", "version", "->", "contentformat", ";", "}", "$", "result", "=", "array", "(", ")", ";", "$", "result", "[", "'pagesection'", "]", "=", "$", "pagesection", ";", "$", "result", "[", "'warnings'", "]", "=", "$", "warnings", ";", "return", "$", "result", ";", "}" ]
Locks and retrieves info of page-section to be edited. @param int $pageid The page ID. @param string $section Section page title. @param boolean $lockonly If true: Just renew lock and not return content. @return array of warnings and page data. @since Moodle 3.1
[ "Locks", "and", "retrieves", "info", "of", "page", "-", "section", "to", "be", "edited", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/wiki/classes/external.php#L830-L896
212,395
moodle/moodle
mod/wiki/classes/external.php
mod_wiki_external.get_page_for_editing_returns
public static function get_page_for_editing_returns() { return new external_single_structure( array( 'pagesection' => new external_single_structure( array( 'content' => new external_value(PARAM_RAW, 'The contents of the page-section to be edited.', VALUE_OPTIONAL), 'contentformat' => new external_value(PARAM_TEXT, 'Format of the original content of the page.', VALUE_OPTIONAL), 'version' => new external_value(PARAM_INT, 'Latest version of the page.'), 'warnings' => new external_warnings() ) ) ) ); }
php
public static function get_page_for_editing_returns() { return new external_single_structure( array( 'pagesection' => new external_single_structure( array( 'content' => new external_value(PARAM_RAW, 'The contents of the page-section to be edited.', VALUE_OPTIONAL), 'contentformat' => new external_value(PARAM_TEXT, 'Format of the original content of the page.', VALUE_OPTIONAL), 'version' => new external_value(PARAM_INT, 'Latest version of the page.'), 'warnings' => new external_warnings() ) ) ) ); }
[ "public", "static", "function", "get_page_for_editing_returns", "(", ")", "{", "return", "new", "external_single_structure", "(", "array", "(", "'pagesection'", "=>", "new", "external_single_structure", "(", "array", "(", "'content'", "=>", "new", "external_value", "(", "PARAM_RAW", ",", "'The contents of the page-section to be edited.'", ",", "VALUE_OPTIONAL", ")", ",", "'contentformat'", "=>", "new", "external_value", "(", "PARAM_TEXT", ",", "'Format of the original content of the page.'", ",", "VALUE_OPTIONAL", ")", ",", "'version'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'Latest version of the page.'", ")", ",", "'warnings'", "=>", "new", "external_warnings", "(", ")", ")", ")", ")", ")", ";", "}" ]
Describes the get_page_for_editing return value. @return external_single_structure @since Moodle 3.1
[ "Describes", "the", "get_page_for_editing", "return", "value", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/wiki/classes/external.php#L904-L919
212,396
moodle/moodle
mod/wiki/classes/external.php
mod_wiki_external.new_page_parameters
public static function new_page_parameters() { return new external_function_parameters ( array( 'title' => new external_value(PARAM_TEXT, 'New page title.'), 'content' => new external_value(PARAM_RAW, 'Page contents.'), 'contentformat' => new external_value(PARAM_TEXT, 'Page contents format. If an invalid format is provided, default wiki format is used.', VALUE_DEFAULT, null), 'subwikiid' => new external_value(PARAM_INT, 'Page\'s subwiki ID.', VALUE_DEFAULT, null), 'wikiid' => new external_value(PARAM_INT, 'Page\'s wiki ID. Used if subwiki does not exists.', VALUE_DEFAULT, null), 'userid' => new external_value(PARAM_INT, 'Subwiki\'s user ID. Used if subwiki does not exists.', VALUE_DEFAULT, null), 'groupid' => new external_value(PARAM_INT, 'Subwiki\'s group ID. Used if subwiki does not exists.', VALUE_DEFAULT, null) ) ); }
php
public static function new_page_parameters() { return new external_function_parameters ( array( 'title' => new external_value(PARAM_TEXT, 'New page title.'), 'content' => new external_value(PARAM_RAW, 'Page contents.'), 'contentformat' => new external_value(PARAM_TEXT, 'Page contents format. If an invalid format is provided, default wiki format is used.', VALUE_DEFAULT, null), 'subwikiid' => new external_value(PARAM_INT, 'Page\'s subwiki ID.', VALUE_DEFAULT, null), 'wikiid' => new external_value(PARAM_INT, 'Page\'s wiki ID. Used if subwiki does not exists.', VALUE_DEFAULT, null), 'userid' => new external_value(PARAM_INT, 'Subwiki\'s user ID. Used if subwiki does not exists.', VALUE_DEFAULT, null), 'groupid' => new external_value(PARAM_INT, 'Subwiki\'s group ID. Used if subwiki does not exists.', VALUE_DEFAULT, null) ) ); }
[ "public", "static", "function", "new_page_parameters", "(", ")", "{", "return", "new", "external_function_parameters", "(", "array", "(", "'title'", "=>", "new", "external_value", "(", "PARAM_TEXT", ",", "'New page title.'", ")", ",", "'content'", "=>", "new", "external_value", "(", "PARAM_RAW", ",", "'Page contents.'", ")", ",", "'contentformat'", "=>", "new", "external_value", "(", "PARAM_TEXT", ",", "'Page contents format. If an invalid format is provided, default\n wiki format is used.'", ",", "VALUE_DEFAULT", ",", "null", ")", ",", "'subwikiid'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'Page\\'s subwiki ID.'", ",", "VALUE_DEFAULT", ",", "null", ")", ",", "'wikiid'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'Page\\'s wiki ID. Used if subwiki does not exists.'", ",", "VALUE_DEFAULT", ",", "null", ")", ",", "'userid'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'Subwiki\\'s user ID. Used if subwiki does not exists.'", ",", "VALUE_DEFAULT", ",", "null", ")", ",", "'groupid'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'Subwiki\\'s group ID. Used if subwiki does not exists.'", ",", "VALUE_DEFAULT", ",", "null", ")", ")", ")", ";", "}" ]
Describes the parameters for new_page. @return external_function_parameters @since Moodle 3.1
[ "Describes", "the", "parameters", "for", "new_page", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/wiki/classes/external.php#L927-L943
212,397
moodle/moodle
mod/wiki/classes/external.php
mod_wiki_external.edit_page_parameters
public static function edit_page_parameters() { return new external_function_parameters ( array( 'pageid' => new external_value(PARAM_INT, 'Page ID.'), 'content' => new external_value(PARAM_RAW, 'Page contents.'), 'section' => new external_value(PARAM_RAW, 'Section page title.', VALUE_DEFAULT, null) ) ); }
php
public static function edit_page_parameters() { return new external_function_parameters ( array( 'pageid' => new external_value(PARAM_INT, 'Page ID.'), 'content' => new external_value(PARAM_RAW, 'Page contents.'), 'section' => new external_value(PARAM_RAW, 'Section page title.', VALUE_DEFAULT, null) ) ); }
[ "public", "static", "function", "edit_page_parameters", "(", ")", "{", "return", "new", "external_function_parameters", "(", "array", "(", "'pageid'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'Page ID.'", ")", ",", "'content'", "=>", "new", "external_value", "(", "PARAM_RAW", ",", "'Page contents.'", ")", ",", "'section'", "=>", "new", "external_value", "(", "PARAM_RAW", ",", "'Section page title.'", ",", "VALUE_DEFAULT", ",", "null", ")", ")", ")", ";", "}" ]
Describes the parameters for edit_page. @return external_function_parameters @since Moodle 3.1
[ "Describes", "the", "parameters", "for", "edit_page", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/wiki/classes/external.php#L1083-L1091
212,398
moodle/moodle
mod/wiki/classes/external.php
mod_wiki_external.edit_page
public static function edit_page($pageid, $content, $section = null) { global $USER; $params = self::validate_parameters(self::edit_page_parameters(), array( 'pageid' => $pageid, 'content' => $content, 'section' => $section ) ); $warnings = array(); // Get wiki page. if (!$page = wiki_get_page($params['pageid'])) { throw new moodle_exception('incorrectpageid', 'wiki'); } // Get wiki instance. if (!$wiki = wiki_get_wiki_from_pageid($params['pageid'])) { throw new moodle_exception('incorrectwikiid', 'wiki'); } // Get subwiki instance. if (!$subwiki = wiki_get_subwiki($page->subwikiid)) { throw new moodle_exception('incorrectsubwikiid', 'wiki'); } // Permission validation. $cm = get_coursemodule_from_instance('wiki', $wiki->id, $wiki->course); $context = context_module::instance($cm->id); self::validate_context($context); if (!wiki_user_can_edit($subwiki)) { throw new moodle_exception('cannoteditpage', 'wiki'); } if (wiki_is_page_section_locked($page->id, $USER->id, $params['section'])) { throw new moodle_exception('pageislocked', 'wiki'); } // Save content. if (!is_null($params['section'])) { $version = wiki_get_current_version($page->id); $content = wiki_parser_proxy::get_section($version->content, $version->contentformat, $params['section'], false); if (!$content) { throw new moodle_exception('invalidsection', 'wiki'); } $save = wiki_save_section($page, $params['section'], $params['content'], $USER->id); } else { $save = wiki_save_page($page, $params['content'], $USER->id); } wiki_delete_locks($page->id, $USER->id, $params['section']); if (!$save) { throw new moodle_exception('savingerror', 'wiki'); } $result = array(); $result['pageid'] = $page->id; $result['warnings'] = $warnings; return $result; }
php
public static function edit_page($pageid, $content, $section = null) { global $USER; $params = self::validate_parameters(self::edit_page_parameters(), array( 'pageid' => $pageid, 'content' => $content, 'section' => $section ) ); $warnings = array(); // Get wiki page. if (!$page = wiki_get_page($params['pageid'])) { throw new moodle_exception('incorrectpageid', 'wiki'); } // Get wiki instance. if (!$wiki = wiki_get_wiki_from_pageid($params['pageid'])) { throw new moodle_exception('incorrectwikiid', 'wiki'); } // Get subwiki instance. if (!$subwiki = wiki_get_subwiki($page->subwikiid)) { throw new moodle_exception('incorrectsubwikiid', 'wiki'); } // Permission validation. $cm = get_coursemodule_from_instance('wiki', $wiki->id, $wiki->course); $context = context_module::instance($cm->id); self::validate_context($context); if (!wiki_user_can_edit($subwiki)) { throw new moodle_exception('cannoteditpage', 'wiki'); } if (wiki_is_page_section_locked($page->id, $USER->id, $params['section'])) { throw new moodle_exception('pageislocked', 'wiki'); } // Save content. if (!is_null($params['section'])) { $version = wiki_get_current_version($page->id); $content = wiki_parser_proxy::get_section($version->content, $version->contentformat, $params['section'], false); if (!$content) { throw new moodle_exception('invalidsection', 'wiki'); } $save = wiki_save_section($page, $params['section'], $params['content'], $USER->id); } else { $save = wiki_save_page($page, $params['content'], $USER->id); } wiki_delete_locks($page->id, $USER->id, $params['section']); if (!$save) { throw new moodle_exception('savingerror', 'wiki'); } $result = array(); $result['pageid'] = $page->id; $result['warnings'] = $warnings; return $result; }
[ "public", "static", "function", "edit_page", "(", "$", "pageid", ",", "$", "content", ",", "$", "section", "=", "null", ")", "{", "global", "$", "USER", ";", "$", "params", "=", "self", "::", "validate_parameters", "(", "self", "::", "edit_page_parameters", "(", ")", ",", "array", "(", "'pageid'", "=>", "$", "pageid", ",", "'content'", "=>", "$", "content", ",", "'section'", "=>", "$", "section", ")", ")", ";", "$", "warnings", "=", "array", "(", ")", ";", "// Get wiki page.", "if", "(", "!", "$", "page", "=", "wiki_get_page", "(", "$", "params", "[", "'pageid'", "]", ")", ")", "{", "throw", "new", "moodle_exception", "(", "'incorrectpageid'", ",", "'wiki'", ")", ";", "}", "// Get wiki instance.", "if", "(", "!", "$", "wiki", "=", "wiki_get_wiki_from_pageid", "(", "$", "params", "[", "'pageid'", "]", ")", ")", "{", "throw", "new", "moodle_exception", "(", "'incorrectwikiid'", ",", "'wiki'", ")", ";", "}", "// Get subwiki instance.", "if", "(", "!", "$", "subwiki", "=", "wiki_get_subwiki", "(", "$", "page", "->", "subwikiid", ")", ")", "{", "throw", "new", "moodle_exception", "(", "'incorrectsubwikiid'", ",", "'wiki'", ")", ";", "}", "// Permission validation.", "$", "cm", "=", "get_coursemodule_from_instance", "(", "'wiki'", ",", "$", "wiki", "->", "id", ",", "$", "wiki", "->", "course", ")", ";", "$", "context", "=", "context_module", "::", "instance", "(", "$", "cm", "->", "id", ")", ";", "self", "::", "validate_context", "(", "$", "context", ")", ";", "if", "(", "!", "wiki_user_can_edit", "(", "$", "subwiki", ")", ")", "{", "throw", "new", "moodle_exception", "(", "'cannoteditpage'", ",", "'wiki'", ")", ";", "}", "if", "(", "wiki_is_page_section_locked", "(", "$", "page", "->", "id", ",", "$", "USER", "->", "id", ",", "$", "params", "[", "'section'", "]", ")", ")", "{", "throw", "new", "moodle_exception", "(", "'pageislocked'", ",", "'wiki'", ")", ";", "}", "// Save content.", "if", "(", "!", "is_null", "(", "$", "params", "[", "'section'", "]", ")", ")", "{", "$", "version", "=", "wiki_get_current_version", "(", "$", "page", "->", "id", ")", ";", "$", "content", "=", "wiki_parser_proxy", "::", "get_section", "(", "$", "version", "->", "content", ",", "$", "version", "->", "contentformat", ",", "$", "params", "[", "'section'", "]", ",", "false", ")", ";", "if", "(", "!", "$", "content", ")", "{", "throw", "new", "moodle_exception", "(", "'invalidsection'", ",", "'wiki'", ")", ";", "}", "$", "save", "=", "wiki_save_section", "(", "$", "page", ",", "$", "params", "[", "'section'", "]", ",", "$", "params", "[", "'content'", "]", ",", "$", "USER", "->", "id", ")", ";", "}", "else", "{", "$", "save", "=", "wiki_save_page", "(", "$", "page", ",", "$", "params", "[", "'content'", "]", ",", "$", "USER", "->", "id", ")", ";", "}", "wiki_delete_locks", "(", "$", "page", "->", "id", ",", "$", "USER", "->", "id", ",", "$", "params", "[", "'section'", "]", ")", ";", "if", "(", "!", "$", "save", ")", "{", "throw", "new", "moodle_exception", "(", "'savingerror'", ",", "'wiki'", ")", ";", "}", "$", "result", "=", "array", "(", ")", ";", "$", "result", "[", "'pageid'", "]", "=", "$", "page", "->", "id", ";", "$", "result", "[", "'warnings'", "]", "=", "$", "warnings", ";", "return", "$", "result", ";", "}" ]
Edit a page contents. @param int $pageid The page ID. @param string $content Page contents. @param int $section Section to be edited. @return array of warnings and page data. @since Moodle 3.1
[ "Edit", "a", "page", "contents", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/wiki/classes/external.php#L1102-L1165
212,399
moodle/moodle
lib/horde/framework/Horde/Crypt/Blowfish.php
Horde_Crypt_Blowfish.setKey
public function setKey($key, $iv = null) { if (!is_string($key)) { throw new Horde_Crypt_Blowfish_Exception('Encryption key must be a string.'); } $len = strlen($key); if (($len > self::MAXKEYSIZE) || ($len == 0)) { throw new Horde_Crypt_Blowfish_Exception(sprintf('Encryption key must be less than %d characters (bytes) and non-zero. Supplied key length: %d', self::MAXKEYSIZE, $len)); } $this->_crypt->key = $key; switch ($this->_crypt->cipher) { case 'cbc': if (is_null($iv)) { if (is_null($this->iv)) { $this->_crypt->setIv(); } } else { $iv = substr($iv, 0, self::IV_LENGTH); if (($len = strlen($iv)) < self::IV_LENGTH) { $iv .= str_repeat(chr(0), self::IV_LENGTH - $len); } $this->_crypt->setIv($iv); } break; case 'ecb': $this->iv = false; break; } }
php
public function setKey($key, $iv = null) { if (!is_string($key)) { throw new Horde_Crypt_Blowfish_Exception('Encryption key must be a string.'); } $len = strlen($key); if (($len > self::MAXKEYSIZE) || ($len == 0)) { throw new Horde_Crypt_Blowfish_Exception(sprintf('Encryption key must be less than %d characters (bytes) and non-zero. Supplied key length: %d', self::MAXKEYSIZE, $len)); } $this->_crypt->key = $key; switch ($this->_crypt->cipher) { case 'cbc': if (is_null($iv)) { if (is_null($this->iv)) { $this->_crypt->setIv(); } } else { $iv = substr($iv, 0, self::IV_LENGTH); if (($len = strlen($iv)) < self::IV_LENGTH) { $iv .= str_repeat(chr(0), self::IV_LENGTH - $len); } $this->_crypt->setIv($iv); } break; case 'ecb': $this->iv = false; break; } }
[ "public", "function", "setKey", "(", "$", "key", ",", "$", "iv", "=", "null", ")", "{", "if", "(", "!", "is_string", "(", "$", "key", ")", ")", "{", "throw", "new", "Horde_Crypt_Blowfish_Exception", "(", "'Encryption key must be a string.'", ")", ";", "}", "$", "len", "=", "strlen", "(", "$", "key", ")", ";", "if", "(", "(", "$", "len", ">", "self", "::", "MAXKEYSIZE", ")", "||", "(", "$", "len", "==", "0", ")", ")", "{", "throw", "new", "Horde_Crypt_Blowfish_Exception", "(", "sprintf", "(", "'Encryption key must be less than %d characters (bytes) and non-zero. Supplied key length: %d'", ",", "self", "::", "MAXKEYSIZE", ",", "$", "len", ")", ")", ";", "}", "$", "this", "->", "_crypt", "->", "key", "=", "$", "key", ";", "switch", "(", "$", "this", "->", "_crypt", "->", "cipher", ")", "{", "case", "'cbc'", ":", "if", "(", "is_null", "(", "$", "iv", ")", ")", "{", "if", "(", "is_null", "(", "$", "this", "->", "iv", ")", ")", "{", "$", "this", "->", "_crypt", "->", "setIv", "(", ")", ";", "}", "}", "else", "{", "$", "iv", "=", "substr", "(", "$", "iv", ",", "0", ",", "self", "::", "IV_LENGTH", ")", ";", "if", "(", "(", "$", "len", "=", "strlen", "(", "$", "iv", ")", ")", "<", "self", "::", "IV_LENGTH", ")", "{", "$", "iv", ".=", "str_repeat", "(", "chr", "(", "0", ")", ",", "self", "::", "IV_LENGTH", "-", "$", "len", ")", ";", "}", "$", "this", "->", "_crypt", "->", "setIv", "(", "$", "iv", ")", ";", "}", "break", ";", "case", "'ecb'", ":", "$", "this", "->", "iv", "=", "false", ";", "break", ";", "}", "}" ]
Sets the secret key. The key must be non-zero, and less than or equal to MAXKEYSIZE characters (bytes) in length. @param string $key Key must be non-empty and less than MAXKEYSIZE bytes in length. @param string $iv The initialization vector to use. Only needed for 'cbc' cipher. If null, an IV is automatically generated. @throws Horde_Crypt_Blowfish_Exception
[ "Sets", "the", "secret", "key", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/horde/framework/Horde/Crypt/Blowfish.php#L144-L176