本文整理汇总了PHP中textlib类的典型用法代码示例。如果您正苦于以下问题:PHP textlib类的具体用法?PHP textlib怎么用?PHP textlib使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了textlib类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: validation
/**
* Form validation
*
* @param array $data
* @param array $files
* @return array $errors An array of errors
*/
function validation($data, $files)
{
global $COURSE, $DB, $CFG;
$errors = parent::validation($data, $files);
$name = trim($data['name']);
if ($data['id'] and $group = $DB->get_record('groups', array('id' => $data['id']))) {
if (textlib::strtolower($group->name) != textlib::strtolower($name)) {
if (groups_get_group_by_name($COURSE->id, $name)) {
$errors['name'] = get_string('groupnameexists', 'group', $name);
}
}
if (!empty($CFG->groupenrolmentkeypolicy) and $data['enrolmentkey'] != '' and $group->enrolmentkey !== $data['enrolmentkey']) {
// enforce password policy only if changing password
$errmsg = '';
if (!check_password_policy($data['enrolmentkey'], $errmsg)) {
$errors['enrolmentkey'] = $errmsg;
}
}
} else {
if (groups_get_group_by_name($COURSE->id, $name)) {
$errors['name'] = get_string('groupnameexists', 'group', $name);
}
}
return $errors;
}
开发者ID:numbas,项目名称:moodle,代码行数:32,代码来源:group_form.php
示例2: definition
function definition() {
$mform = $this->_form;
$mform->addElement('header', 'settingsheader', get_string('upload'));
$mform->addElement('filepicker', 'userfile', get_string('file'));
$mform->addRule('userfile', null, 'required');
$choices = csv_import_reader::get_delimiter_list();
$mform->addElement('select', 'delimiter_name', get_string('csvdelimiter', 'local_users'), $choices);
if (array_key_exists('cfg', $choices)) {
$mform->setDefault('delimiter_name', 'cfg');
} else if (get_string('listsep', 'langconfig') == ';') {
$mform->setDefault('delimiter_name', 'semicolon');
} else {
$mform->setDefault('delimiter_name', 'comma');
}
$choices = textlib::get_encodings();
$mform->addElement('select', 'encoding', get_string('encoding', 'local_users'), $choices);
$mform->setDefault('encoding', 'UTF-8');
$choices = array('10' => 10, '20' => 20, '100' => 100, '1000' => 1000, '100000' => 100000);
$mform->addElement('select', 'previewrows', get_string('rowpreviewnum', 'local_users'), $choices);
$mform->setType('previewrows', PARAM_INT);
$this->add_action_buttons(true, get_string('upload'));
}
开发者ID:narasimhaeabyas,项目名称:tataaiapro,代码行数:28,代码来源:upload_users_form.php
示例3: validation
/**
* Form validation
*
* @param array $data
* @param array $files
* @return array $errors An array of validataion errors for the form.
*/
function validation($data, $files)
{
global $COURSE, $DB;
$errors = parent::validation($data, $files);
$name = trim($data['name']);
if (isset($data['idnumber'])) {
$idnumber = trim($data['idnumber']);
} else {
$idnumber = '';
}
if ($data['id'] and $grouping = $DB->get_record('groupings', array('id' => $data['id']))) {
if (textlib::strtolower($grouping->name) != textlib::strtolower($name)) {
if (groups_get_grouping_by_name($COURSE->id, $name)) {
$errors['name'] = get_string('groupingnameexists', 'group', $name);
}
}
if (!empty($idnumber) && $grouping->idnumber != $idnumber) {
if (groups_get_grouping_by_idnumber($COURSE->id, $idnumber)) {
$errors['idnumber'] = get_string('idnumbertaken');
}
}
} else {
if (groups_get_grouping_by_name($COURSE->id, $name)) {
$errors['name'] = get_string('groupingnameexists', 'group', $name);
} else {
if (!empty($idnumber) && groups_get_grouping_by_idnumber($COURSE->id, $idnumber)) {
$errors['idnumber'] = get_string('idnumbertaken');
}
}
}
return $errors;
}
开发者ID:saurabh947,项目名称:MoodleLearning,代码行数:39,代码来源:grouping_form.php
示例4: definition
public function definition()
{
global $CFG, $USER;
$mform =& $this->_form;
$mform->addElement('header', 'settingsheader', get_string('upload'));
$mform->addElement('filepicker', 'userfile', get_string('file'));
$mform->addRule('userfile', null, 'required');
$choices = csv_import_reader::get_delimiter_list();
$mform->addElement('select', 'delimiter_name', get_string('csvdelimiter', 'tool_uploaduser'), $choices);
if (array_key_exists('cfg', $choices)) {
$mform->setDefault('delimiter_name', 'cfg');
} else {
if (get_string('listsep', 'langconfig') == ';') {
$mform->setDefault('delimiter_name', 'semicolon');
} else {
$mform->setDefault('delimiter_name', 'comma');
}
}
$choices = textlib::get_encodings();
$mform->addElement('select', 'encoding', get_string('encoding', 'tool_uploaduser'), $choices);
$mform->setDefault('encoding', 'UTF-8');
$choices = array('10' => 10, '20' => 20, '100' => 100, '1000' => 1000, '100000' => 100000);
$mform->addElement('select', 'previewrows', get_string('rowpreviewnum', 'tool_uploaduser'), $choices);
$mform->setType('previewrows', PARAM_INT);
$choices = array(UU_ADDNEW => get_string('uuoptype_addnew', 'tool_uploaduser'), UU_ADDINC => get_string('uuoptype_addinc', 'tool_uploaduser'), UU_ADD_UPDATE => get_string('uuoptype_addupdate', 'tool_uploaduser'), UU_UPDATE => get_string('uuoptype_update', 'tool_uploaduser'));
$mform->addElement('select', 'uutype', get_string('uuoptype', 'tool_uploaduser'), $choices);
$this->add_action_buttons(false, get_string('uploadusers', 'tool_uploaduser'));
}
开发者ID:sumitnegi933,项目名称:Moodle_lms_New,代码行数:28,代码来源:uploaduser_form.php
示例5: definition
function definition() {
global $CFG;
$mform = & $this->_form;
$course = $this->_customdata['course'];
$context = $this->_customdata['context'];
// the upload manager is used directly in post precessing, moodleform::save_files() is not used yet
//$this->set_upload_manager(new upload_manager('attachment'));
$mform->addElement('header', 'general', ''); //fill in the data depending on page params
//later using set_data
$mform->addElement('filepicker', 'attachment', get_string('location', 'enrol_flatfile'));
$mform->addRule('attachment', null, 'required');
$choices = csv_import_reader::get_delimiter_list();
$mform->addElement('select', 'delimiter_name', get_string('csvdelimiter', 'tool_uploaduser'), $choices);
if (array_key_exists('cfg', $choices)) {
$mform->setDefault('delimiter_name', 'cfg');
} else if (get_string('listsep', 'langconfig') == ';') {
$mform->setDefault('delimiter_name', 'semicolon');
} else {
$mform->setDefault('delimiter_name', 'comma');
}
$choices = textlib::get_encodings();
$mform->addElement('select', 'encoding', get_string('encoding', 'tool_uploaduser'), $choices);
$mform->setDefault('encoding', 'UTF-8');
$roles = get_assignable_roles($context);
$mform->addElement('select', 'roleassign', get_string('roleassign', 'local_mass_enroll'), $roles);
$mform->setDefault('roleassign', 5); //student
$ids = array (
'idnumber' => get_string('idnumber', 'local_mass_enroll'),
'username' => get_string('username', 'local_mass_enroll'),
'email' => get_string('email')
);
$mform->addElement('select', 'firstcolumn', get_string('firstcolumn', 'local_mass_enroll'), $ids);
$mform->setDefault('firstcolumn', 'idnumber');
$mform->addElement('selectyesno', 'creategroups', get_string('creategroups', 'local_mass_enroll'));
$mform->setDefault('creategroups', 1);
$mform->addElement('selectyesno', 'creategroupings', get_string('creategroupings', 'local_mass_enroll'));
$mform->setDefault('creategroupings', 1);
$mform->addElement('selectyesno', 'mailreport', get_string('mailreport', 'local_mass_enroll'));
$mform->setDefault('mailreport', 1);
//-------------------------------------------------------------------------------
// buttons
$this->add_action_buttons(true, get_string('enroll', 'local_mass_enroll'));
$mform->addElement('hidden', 'id', $course->id);
$mform->setType('id', PARAM_INT);
}
开发者ID:narasimhaeabyas,项目名称:tataaiapro,代码行数:60,代码来源:mass_enroll_form.php
示例6: csv_quote
function csv_quote($value) {
global $excel;
if ($excel) {
return textlib::convert('"'.str_replace('"',"'",$value).'"','UTF-8','UTF-16LE');
} else {
return '"'.str_replace('"',"'",$value).'"';
}
}
开发者ID:Jtgadbois,项目名称:Pedadida,代码行数:8,代码来源:index.php
示例7: definition
function definition() {
$mform =& $this->_form;
$mform->addElement('file', 'userfile', get_string('csvtextfile', 'facetoface'));
$mform->setType('userfile', PARAM_FILE);
$mform->addRule('userfile', null, 'required');
$encodings = textlib::get_encodings();
$mform->addElement('select', 'encoding', get_string('encoding', 'grades'), $encodings);
$mform->addElement('checkbox', 'suppressemail', '', get_string('suppressemailforattendees', 'facetoface'));
}
开发者ID:narasimhaeabyas,项目名称:tataaiapro,代码行数:9,代码来源:bulkadd_attendees.php
示例8: validate
/**
* Validates a value using a range comparison
*
* @param string $value Value to be checked
* @param mixed $options Int for length, array for range
* @access public
* @return boolean true if value is valid
*/
function validate($value, $options = null)
{
$length = textlib::strlen($value);
switch ($this->name) {
case 'minlength':
return $length >= $options;
case 'maxlength':
return $length <= $options;
default:
return $length >= $options[0] && $length <= $options[1];
}
}
开发者ID:masaterutakeno,项目名称:MoodleMobile,代码行数:20,代码来源:Range.php
示例9: EncodeHeader
/**
* Use internal moodles own textlib to encode mimeheaders.
* Fall back to phpmailers inbuilt functions if not
*/
public function EncodeHeader($str, $position = 'text')
{
$encoded = textlib::encode_mimeheader($str, $this->CharSet);
if ($encoded !== false) {
$encoded = str_replace("\n", $this->LE, $encoded);
if ($position == 'phrase') {
return "\"{$encoded}\"";
}
return $encoded;
}
return parent::EncodeHeader($str, $position);
}
开发者ID:masaterutakeno,项目名称:MoodleMobile,代码行数:16,代码来源:moodle_phpmailer.php
示例10: get_label_name
/**
* @uses LABEL_MAX_NAME_LENGTH
* @param object $label
* @return string
*/
function get_label_name($label) {
$name = strip_tags(format_string($label->intro,true));
if (textlib::strlen($name) > LABEL_MAX_NAME_LENGTH) {
$name = textlib::substr($name, 0, LABEL_MAX_NAME_LENGTH)."...";
}
if (empty($name)) {
// arbitrary name
$name = get_string('modulename','label');
}
return $name;
}
开发者ID:Jtgadbois,项目名称:Pedadida,代码行数:18,代码来源:lib.php
示例11: game_cross_new
function game_cross_new($game, $attemptid, &$crossm)
{
global $DB, $USER;
$cross = new CrossDB();
$questions = array();
$infos = array();
$answers = array();
$recs = game_questions_shortanswer($game);
if ($recs == false) {
print_error('game_cross_continue: ' . get_string('no_words', 'game'));
}
$infos = array();
$reps = array();
foreach ($recs as $rec) {
if ($game->param7 == false) {
if (textlib::strpos($rec->answertext, ' ')) {
continue;
//spaces not allowed
}
}
$rec->answertext = game_upper($rec->answertext);
$answers[$rec->answertext] = game_repairquestion($rec->questiontext);
$infos[$rec->answertext] = array($game->sourcemodule, $rec->questionid, $rec->glossaryentryid, $rec->attachment);
$a = array('gameid' => $game->id, 'userid' => $USER->id, 'questionid' => $rec->questionid, 'glossaryentryid' => $rec->glossaryentryid);
if (($rec2 = $DB->get_record('game_repetitions', $a, 'id,repetitions r')) != false) {
$reps[$rec->answertext] = $rec2->r;
}
}
$cross->setwords($answers, $game->param1, $reps);
//game->param2 is maximum words in crossword
if ($cross->computedata($crossm, $crossd, $lettets, $game->param2)) {
$new_crossd = array();
foreach ($crossd as $rec) {
$info = $infos[$rec->answertext];
if ($info != false) {
$rec->sourcemodule = $info[0];
$rec->questionid = $info[1];
$rec->glossaryentryid = $info[2];
$rec->attachment = $info[3];
}
$new_crossd[] = $rec;
}
$cross->savecross($game, $crossm, $new_crossd, $attemptid);
}
if (count($crossd) == 0) {
print_error('game_cross_continue: ' . get_string('no_words', 'game'));
}
}
开发者ID:vinoth4891,项目名称:clinique,代码行数:48,代码来源:play.php
示例12: definition
function definition()
{
global $COURSE;
$mform =& $this->_form;
if (isset($this->_customdata)) {
// hardcoding plugin names here is hacky
$features = $this->_customdata;
} else {
$features = array();
}
// course id needs to be passed for auth purposes
$mform->addElement('hidden', 'id', optional_param('id', 0, PARAM_INT));
$mform->setType('id', PARAM_INT);
$mform->addElement('header', 'general', get_string('importfile', 'grades'));
// Restrict the possible upload file types.
if (!empty($features['acceptedtypes'])) {
$acceptedtypes = $features['acceptedtypes'];
} else {
$acceptedtypes = '*';
}
// File upload.
$mform->addElement('filepicker', 'userfile', get_string('file'), null, array('accepted_types' => $acceptedtypes));
$mform->addRule('userfile', null, 'required');
$encodings = textlib::get_encodings();
$mform->addElement('select', 'encoding', get_string('encoding', 'grades'), $encodings);
if (!empty($features['includeseparator'])) {
$radio = array();
$radio[] = $mform->createElement('radio', 'separator', null, get_string('septab', 'grades'), 'tab');
$radio[] = $mform->createElement('radio', 'separator', null, get_string('sepcomma', 'grades'), 'comma');
$radio[] = $mform->createElement('radio', 'separator', null, get_string('sepcolon', 'grades'), 'colon');
$radio[] = $mform->createElement('radio', 'separator', null, get_string('sepsemicolon', 'grades'), 'semicolon');
$mform->addGroup($radio, 'separator', get_string('separator', 'grades'), ' ', false);
$mform->setDefault('separator', 'comma');
}
if (!empty($features['verbosescales'])) {
$options = array(1 => get_string('yes'), 0 => get_string('no'));
$mform->addElement('select', 'verbosescales', get_string('verbosescales', 'grades'), $options);
}
$options = array('10' => 10, '20' => 20, '100' => 100, '1000' => 1000, '100000' => 100000);
$mform->addElement('select', 'previewrows', get_string('rowpreviewnum', 'grades'), $options);
// TODO: localize
$mform->setType('previewrows', PARAM_INT);
$mform->addElement('hidden', 'groupid', groups_get_course_group($COURSE));
$mform->setType('groupid', PARAM_INT);
$this->add_action_buttons(false, get_string('uploadgrades', 'grades'));
}
开发者ID:masaterutakeno,项目名称:MoodleMobile,代码行数:46,代码来源:grade_import_form.php
示例13: validation
public function validation($data, $files)
{
global $DB, $CFG;
$errors = parent::validation($data, $files);
$instance = $this->instance;
if ($instance->password !== '') {
if ($data['guestpassword'] !== $instance->password) {
$plugin = enrol_get_plugin('guest');
if ($plugin->get_config('showhint')) {
$hint = textlib::substr($instance->password, 0, 1);
$errors['guestpassword'] = get_string('passwordinvalidhint', 'enrol_guest', $hint);
} else {
$errors['guestpassword'] = get_string('passwordinvalid', 'enrol_guest');
}
}
}
return $errors;
}
开发者ID:JP-Git,项目名称:moodle,代码行数:18,代码来源:locallib.php
示例14: action
protected function action($message, $level, $options = null)
{
$columns = $this->columns;
if ($this->datecol) {
$columns[$this->datecol] = time();
}
if ($this->levelcol) {
$columns[$this->levelcol] = $level;
}
$message = clean_param($message, PARAM_NOTAGS);
// Check if the message exceeds the 255 character limit in the database,
// if it does, shorten it so that it can be inserted successfully.
if (textlib::strlen($message) > 255) {
$message = textlib::substr($message, 0, 252) . '...';
}
$columns[$this->messagecol] = $message;
return $this->insert_log_record($this->logtable, $columns);
}
开发者ID:verbazend,项目名称:AWFA,代码行数:18,代码来源:database_logger.class.php
示例15: check_table
protected function check_table(xmldb_table $xmldb_table, array $metacolumns)
{
global $DB;
$o = '';
$wrong_fields = array();
// Get and process XMLDB fields
if ($xmldb_fields = $xmldb_table->getFields()) {
$o .= '<ul>';
foreach ($xmldb_fields as $xmldb_field) {
// Get the type of the column, we only will process CHAR (VARCHAR2) ones
if ($xmldb_field->getType() != XMLDB_TYPE_CHAR) {
continue;
}
$o .= '<li>' . $this->str['field'] . ': ' . $xmldb_field->getName() . ' ';
// Get current semantic from dictionary, we only will process B (BYTE) ones
// suplying the SQL code to change them to C (CHAR) semantic
$params = array('table_name' => textlib::strtoupper($DB->get_prefix() . $xmldb_table->getName()), 'column_name' => textlib::strtoupper($xmldb_field->getName()), 'data_type' => 'VARCHAR2');
$currentsemantic = $DB->get_field_sql('
SELECT char_used
FROM user_tab_columns
WHERE table_name = :table_name
AND column_name = :column_name
AND data_type = :data_type', $params);
// If using byte semantics, we'll need to change them to char semantics
if ($currentsemantic == 'B') {
$info = '(' . $this->str['expected'] . " 'CHAR', " . $this->str['actual'] . " 'BYTE')";
$o .= '<font color="red">' . $this->str['wrong'] . " {$info}</font>";
// Add the wrong field to the list
$obj = new stdClass();
$obj->table = $xmldb_table;
$obj->field = $xmldb_field;
$wrong_fields[] = $obj;
} else {
$o .= '<font color="green">' . $this->str['ok'] . '</font>';
}
$o .= '</li>';
}
$o .= '</ul>';
}
return array($o, $wrong_fields);
}
开发者ID:JP-Git,项目名称:moodle,代码行数:41,代码来源:check_oracle_semantics.class.php
示例16: user_update_user
/**
* Update a user with a user object (will compare against the ID)
*
* @param object $user the user to update
*/
function user_update_user($user)
{
global $DB;
// set the timecreate field to the current time
if (!is_object($user)) {
$user = (object) $user;
}
//check username
if (isset($user->username)) {
if ($user->username !== textlib::strtolower($user->username)) {
throw new moodle_exception('usernamelowercase');
} else {
if ($user->username !== clean_param($user->username, PARAM_USERNAME)) {
throw new moodle_exception('invalidusername');
}
}
}
// unset password here, for updating later
if (isset($user->password)) {
//check password toward the password policy
if (!check_password_policy($user->password, $errmsg)) {
throw new moodle_exception($errmsg);
}
$passwd = $user->password;
unset($user->password);
}
$user->timemodified = time();
$DB->update_record('user', $user);
// trigger user_updated event on the full database user row
$updateduser = $DB->get_record('user', array('id' => $user->id));
// if password was set, then update its hash
if (isset($passwd)) {
$authplugin = get_auth_plugin($updateduser->auth);
if ($authplugin->can_change_password()) {
$authplugin->user_update_password($updateduser, $passwd);
}
}
events_trigger('user_updated', $updateduser);
add_to_log(SITEID, 'user', get_string('update'), '/view.php?id=' . $updateduser->id, fullname($updateduser));
}
开发者ID:nmicha,项目名称:moodle,代码行数:45,代码来源:lib.php
示例17: definition
function definition() {
global $CFG;
$mform = & $this->_form;
//$mform->addElement('header', 'general', get_string('bulkenrol','block_learning_plan')); //fill in the data depending on page params
//later using set_data
$mform->addElement('filepicker', 'attachment', get_string('location', 'enrol_flatfile'));
$mform->addRule('attachment', null, 'required');
$choices = csv_import_reader::get_delimiter_list();
$mform->addElement('select', 'delimiter_name', get_string('csvdelimiter', 'tool_uploaduser'), $choices);
if (array_key_exists('cfg', $choices)) {
$mform->setDefault('delimiter_name', 'cfg');
} else if (get_string('listsep', 'langconfig') == ';') {
$mform->setDefault('delimiter_name', 'semicolon');
} else {
$mform->setDefault('delimiter_name', 'comma');
}
$choices = textlib::get_encodings();
$mform->addElement('select', 'encoding', get_string('encoding', 'tool_uploaduser'), $choices);
$mform->setDefault('encoding', 'UTF-8');
$mform->addElement('hidden','roleassign');
$mform->setDefault('roleassign', 5); //student
$mform->setType('roleassign','int');
$ids = array (
'username' => get_string('username', 'local_mass_enroll'),
'idnumber' => get_string('idnumber', 'local_mass_enroll'),
'email' => get_string('email')
);
$mform->addElement('select', 'firstcolumn', get_string('firstcolumn', 'block_learning_plan'), $ids);
$mform->setDefault('firstcolumn', 'username');
//$mform->addElement('selectyesno', 'mailreport', get_string('mailreport', 'local_mass_enroll'));
//$mform->setDefault('mailreport', 1);
$this->add_action_buttons(true, get_string('enroll_lp', 'block_learning_plan'));
}
开发者ID:narasimhaeabyas,项目名称:tataaiapro,代码行数:40,代码来源:bulk_enroll_form.php
示例18: rfc2445_fold
function rfc2445_fold($string)
{
if (textlib::strlen($string, 'utf-8') <= RFC2445_FOLDED_LINE_LENGTH) {
return $string;
}
$retval = '';
$i = 0;
$len_count = 0;
//multi-byte string, get the correct length
$section_len = textlib::strlen($string, 'utf-8');
while ($len_count < $section_len) {
//get the current portion of the line
$section = textlib::substr($string, $i * RFC2445_FOLDED_LINE_LENGTH, RFC2445_FOLDED_LINE_LENGTH, 'utf-8');
//increment the length we've processed by the length of the new portion
$len_count += textlib::strlen($section, 'utf-8');
/* Add the portion to the return value, terminating with CRLF.HTAB
As per RFC 2445, CRLF.HTAB will be replaced by the processor of the
data */
$retval .= $section . RFC2445_CRLF . RFC2445_WSP;
$i++;
}
return $retval;
}
开发者ID:masaterutakeno,项目名称:MoodleMobile,代码行数:23,代码来源:iCalendar_rfc2445.php
示例19: definition
function definition() {
global $CFG;
$mform =& $this->_form;
$cmid = $this->_customdata['id'];
$mform->addElement('filepicker', 'recordsfile', get_string('csvfile', 'data'));
$delimiters = csv_import_reader::get_delimiter_list();
$mform->addElement('select', 'fielddelimiter', get_string('fielddelimiter', 'data'), $delimiters);
$mform->setDefault('fielddelimiter', 'comma');
$mform->addElement('text', 'fieldenclosure', get_string('fieldenclosure', 'data'));
$choices = textlib::get_encodings();
$mform->addElement('select', 'encoding', get_string('fileencoding', 'mod_data'), $choices);
$mform->setDefault('encoding', 'UTF-8');
$submit_string = get_string('submit');
// data id
$mform->addElement('hidden', 'd');
$mform->setType('d', PARAM_INT);
$this->add_action_buttons(false, $submit_string);
}
开发者ID:JP-Git,项目名称:moodle,代码行数:24,代码来源:import_form.php
示例20: mod_giportfolio_migrate_moddata_dir_to_legacy
/**
* Migrate giportfolio files stored in moddata folders.
*
* Please note it was a big mistake to store the files there in the first place!
*
* @param stdClass $giportfolio
* @param stdClass $context
* @param string $path
* @return void
*/
function mod_giportfolio_migrate_moddata_dir_to_legacy($giportfolio, $context, $path)
{
global $OUTPUT, $CFG;
$base = "{$CFG->dataroot}/{$giportfolio->course}/{$CFG->moddata}/giportfolio/{$giportfolio->id}";
$fulldir = $base . $path;
if (!is_dir($fulldir)) {
// Does not exist.
return;
}
$fs = get_file_storage();
$items = new DirectoryIterator($fulldir);
foreach ($items as $item) {
if ($item->isDot()) {
unset($item);
// Release file handle.
continue;
}
if ($item->isLink()) {
// Do not follow symlinks - they were never supported in moddata, sorry.
unset($item);
// Release file handle.
continue;
}
if ($item->isFile()) {
if (!$item->isReadable()) {
echo $OUTPUT->notification(" File not readable, skipping: " . $fulldir . $item->getFilename());
unset($item);
// Release file handle.
continue;
}
$filepath = clean_param("/{$CFG->moddata}/giportfolio/{$giportfolio->id}" . $path, PARAM_PATH);
$filename = clean_param($item->getFilename(), PARAM_FILE);
if ($filename === '') {
// Unsupported chars, sorry.
unset($item);
// Release file handle.
continue;
}
if (textlib::strlen($filepath) > 255) {
echo $OUTPUT->notification(" File path longer than 255 chars, skipping: " . $fulldir . $item->getFilename());
unset($item);
// Release file handle.
continue;
}
if (!$fs->file_exists($context->id, 'course', 'legacy', '0', $filepath, $filename)) {
$filerecord = array('contextid' => $context->id, 'component' => 'course', 'filearea' => 'legacy', 'itemid' => 0, 'filepath' => $filepath, 'filename' => $filename, 'timecreated' => $item->getCTime(), 'timemodified' => $item->getMTime());
$fs->create_file_from_pathname($filerecord, $fulldir . $item->getFilename());
}
$oldpathname = $fulldir . $item->getFilename();
unset($item);
// Release file handle.
@unlink($oldpathname);
} else {
// Migrate recursively all subdirectories.
$oldpathname = $base . $item->getFilename() . '/';
$subpath = $path . $item->getFilename() . '/';
unset($item);
// Release file handle.
giportfolio_migrate_moddata_dir_to_legacy($giportfolio, $context, $subpath);
@rmdir($oldpathname);
// Deletes dir if empty.
}
}
unset($items);
// Release file handles.
}
开发者ID:andrewhancox,项目名称:moodle-mod_giportfolio,代码行数:76,代码来源:upgradelib.php
注:本文中的textlib类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论