当前位置: 首页>>代码示例>>PHP>>正文


PHP core_text::convert方法代码示例

本文整理汇总了PHP中core_text::convert方法的典型用法代码示例。如果您正苦于以下问题:PHP core_text::convert方法的具体用法?PHP core_text::convert怎么用?PHP core_text::convert使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在core_text的用法示例。


在下文中一共展示了core_text::convert方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: iplookup_find_location

/**
 * Returns location information
 * @param string $ip
 * @return array
 */
function iplookup_find_location($ip)
{
    global $CFG;
    $info = array('city' => null, 'country' => null, 'longitude' => null, 'latitude' => null, 'error' => null, 'note' => '', 'title' => array());
    if (!empty($CFG->geoip2file) and file_exists($CFG->geoip2file)) {
        $reader = new GeoIp2\Database\Reader($CFG->geoip2file);
        $record = $reader->city($ip);
        if (empty($record)) {
            $info['error'] = get_string('iplookupfailed', 'error', $ip);
            return $info;
        }
        $info['city'] = core_text::convert($record->city->name, 'iso-8859-1', 'utf-8');
        $info['title'][] = $info['city'];
        $countrycode = $record->country->isoCode;
        $countries = get_string_manager()->get_list_of_countries(true);
        if (isset($countries[$countrycode])) {
            // Prefer our localized country names.
            $info['country'] = $countries[$countrycode];
        } else {
            $info['country'] = $record->country->names['en'];
        }
        $info['title'][] = $info['country'];
        $info['longitude'] = $record->location->longitude;
        $info['latitude'] = $record->location->latitude;
        $info['note'] = get_string('iplookupmaxmindnote', 'admin');
        return $info;
    } else {
        require_once $CFG->libdir . '/filelib.php';
        if (strpos($ip, ':') !== false) {
            // IPv6 is not supported by geoplugin.net.
            $info['error'] = get_string('invalidipformat', 'error');
            return $info;
        }
        $ipdata = download_file_content('http://www.geoplugin.net/json.gp?ip=' . $ip);
        if ($ipdata) {
            $ipdata = preg_replace('/^geoPlugin\\((.*)\\)\\s*$/s', '$1', $ipdata);
            $ipdata = json_decode($ipdata, true);
        }
        if (!is_array($ipdata)) {
            $info['error'] = get_string('cannotgeoplugin', 'error');
            return $info;
        }
        $info['latitude'] = (double) $ipdata['geoplugin_latitude'];
        $info['longitude'] = (double) $ipdata['geoplugin_longitude'];
        $info['city'] = s($ipdata['geoplugin_city']);
        $countrycode = $ipdata['geoplugin_countryCode'];
        $countries = get_string_manager()->get_list_of_countries(true);
        if (isset($countries[$countrycode])) {
            // prefer our localized country names
            $info['country'] = $countries[$countrycode];
        } else {
            $info['country'] = s($ipdata['geoplugin_countryName']);
        }
        $info['note'] = get_string('iplookupgeoplugin', 'admin');
        $info['title'][] = $info['city'];
        $info['title'][] = $info['country'];
        return $info;
    }
}
开发者ID:gabrielrosset,项目名称:moodle,代码行数:64,代码来源:lib.php

示例2: quote

 /**
  * Gets quoted csv variable string.
  *
  * @param string $varstr csv variable string
  * @return quoted csv variable string
  */
 public function quote($varstr)
 {
     if ($this->_excelcsv) {
         return core_text::convert('"' . str_replace('"', "'", $varstr) . '"', 'UTF-8', 'UTF-16LE');
     } else {
         return '"' . str_replace('"', "'", $varstr) . '"';
     }
 }
开发者ID:michaudg,项目名称:moodle-mod_ouwiki,代码行数:14,代码来源:csv_writer.php

示例3: csv_quote

function csv_quote($value)
{
    global $excel;
    if ($excel) {
        return core_text::convert('"' . str_replace('"', "'", $value) . '"', 'UTF-8', 'UTF-16LE');
    } else {
        return '"' . str_replace('"', "'", $value) . '"';
    }
}
开发者ID:MoodleMetaData,项目名称:MoodleMetaData,代码行数:9,代码来源:index.php

示例4: user_login

 /**
  * Authenticates user against the selected authentication provide (Ad web service)
  *
  * @param string $username The username (with system magic quotes)
  * @param string $password The password (with system magic quotes)
  * @return bool Authentication success or failure.
  */
 function user_login($username, $password)
 {
     global $DB, $CFG;
     $extusername = core_text::convert($username, 'utf-8', $this->config->extencoding);
     $extpassword = core_text::convert($password, 'utf-8', $this->config->extencoding);
     if (!$username or !$password) {
         // Don't allow blank usernames or passwords
         return false;
     }
     //retrieve the user matching username
     if ($user = $DB->get_record('user', array('username' => $username, 'mnethostid' => $CFG->mnet_localhost_id, 'auth' => $this->authtype))) {
         return validate_internal_user_password($user, $password);
     } else {
         return false;
     }
     //username must exist and have the right authentication method
     if (!empty($user) && $user->auth == 'adwebservice') {
         return true;
     }
     return false;
 }
开发者ID:narasimhaeabyas,项目名称:tataaiapro,代码行数:28,代码来源:auth.php

示例5: process_file

 /**
  * Process flatfile.
  * @param progress_trace $trace
  * @return bool true if any data processed, false if not
  */
 protected function process_file(progress_trace $trace)
 {
     global $CFG, $DB;
     // We may need more memory here.
     core_php_time_limit::raise();
     raise_memory_limit(MEMORY_HUGE);
     $filelocation = $this->get_config('location');
     if (empty($filelocation)) {
         // Default legacy location.
         $filelocation = "{$CFG->dataroot}/1/enrolments.txt";
     }
     $disclosefile = $this->obfuscate_filepath($filelocation);
     if (!file_exists($filelocation)) {
         $trace->output("Flatfile enrolments file not found: {$disclosefile}");
         $trace->finished();
         return false;
     }
     $trace->output("Processing flat file enrolments from: {$disclosefile} ...");
     $content = file_get_contents($filelocation);
     if ($content !== false) {
         $rolemap = $this->get_role_map($trace);
         $content = core_text::convert($content, $this->get_config('encoding', 'utf-8'), 'utf-8');
         $content = str_replace("\r", '', $content);
         $content = explode("\n", $content);
         $line = 0;
         foreach ($content as $fields) {
             $line++;
             if (trim($fields) === '') {
                 // Empty lines are ignored.
                 continue;
             }
             // Deal with different separators.
             if (strpos($fields, ',') !== false) {
                 $fields = explode(',', $fields);
             } else {
                 $fields = explode(';', $fields);
             }
             // If a line is incorrectly formatted ie does not have 4 comma separated fields then ignore it.
             if (count($fields) < 4 or count($fields) > 6) {
                 $trace->output("Line incorrectly formatted - ignoring {$line}", 1);
                 continue;
             }
             $fields[0] = trim(core_text::strtolower($fields[0]));
             $fields[1] = trim(core_text::strtolower($fields[1]));
             $fields[2] = trim($fields[2]);
             $fields[3] = trim($fields[3]);
             $fields[4] = isset($fields[4]) ? (int) trim($fields[4]) : 0;
             $fields[5] = isset($fields[5]) ? (int) trim($fields[5]) : 0;
             // Deal with quoted values - all or nothing, we need to support "' in idnumbers, sorry.
             if (strpos($fields[0], "'") === 0) {
                 foreach ($fields as $k => $v) {
                     $fields[$k] = trim($v, "'");
                 }
             } else {
                 if (strpos($fields[0], '"') === 0) {
                     foreach ($fields as $k => $v) {
                         $fields[$k] = trim($v, '"');
                     }
                 }
             }
             $trace->output("{$line}: {$fields['0']}, {$fields['1']}, {$fields['2']}, {$fields['3']}, {$fields['4']}, {$fields['5']}", 1);
             // Check correct formatting of operation field.
             if ($fields[0] !== "add" and $fields[0] !== "del") {
                 $trace->output("Unknown operation in field 1 - ignoring line {$line}", 1);
                 continue;
             }
             // Check correct formatting of role field.
             if (!isset($rolemap[$fields[1]])) {
                 $trace->output("Unknown role in field2 - ignoring line {$line}", 1);
                 continue;
             }
             $roleid = $rolemap[$fields[1]];
             if (empty($fields[2]) or !($user = $DB->get_record("user", array("idnumber" => $fields[2], 'deleted' => 0)))) {
                 $trace->output("Unknown user idnumber or deleted user in field 3 - ignoring line {$line}", 1);
                 continue;
             }
             if (!($course = $DB->get_record("course", array("idnumber" => $fields[3])))) {
                 $trace->output("Unknown course idnumber in field 4 - ignoring line {$line}", 1);
                 continue;
             }
             if ($fields[4] > $fields[5] and $fields[5] != 0) {
                 $trace->output("Start time was later than end time - ignoring line {$line}", 1);
                 continue;
             }
             $this->process_records($trace, $fields[0], $roleid, $user, $course, $fields[4], $fields[5]);
         }
         unset($content);
     }
     if (!unlink($filelocation)) {
         $eventdata = new stdClass();
         $eventdata->modulename = 'moodle';
         $eventdata->component = 'enrol_flatfile';
         $eventdata->name = 'flatfile_enrolment';
         $eventdata->userfrom = get_admin();
         $eventdata->userto = get_admin();
//.........这里部分代码省略.........
开发者ID:evltuma,项目名称:moodle,代码行数:101,代码来源:lib.php

示例6: init_namelookup

 /**
  * Create a map of file names used in zip archive.
  * @return void
  */
 protected function init_namelookup()
 {
     if ($this->emptyziphack) {
         $this->namelookup = array();
         return;
     }
     if (!isset($this->za)) {
         return;
     }
     if (isset($this->namelookup)) {
         return;
     }
     $this->namelookup = array();
     if ($this->mode != file_archive::OPEN) {
         // No need to tweak existing names when creating zip file because there are none yet!
         return;
     }
     if (!file_exists($this->archivepathname)) {
         return;
     }
     if (!($fp = fopen($this->archivepathname, 'rb'))) {
         return;
     }
     if (!($filesize = filesize($this->archivepathname))) {
         return;
     }
     $centralend = self::zip_get_central_end($fp, $filesize);
     if ($centralend === false or $centralend['disk'] !== 0 or $centralend['disk_start'] !== 0 or $centralend['offset'] === 0xffffffff) {
         // Single disk archives only and o support for ZIP64, sorry.
         fclose($fp);
         return;
     }
     fseek($fp, $centralend['offset']);
     $data = fread($fp, $centralend['size']);
     $pos = 0;
     $files = array();
     for ($i = 0; $i < $centralend['entries']; $i++) {
         $file = self::zip_parse_file_header($data, $centralend, $pos);
         if ($file === false) {
             // Wrong header, sorry.
             fclose($fp);
             return;
         }
         $files[] = $file;
     }
     fclose($fp);
     foreach ($files as $file) {
         $name = $file['name'];
         if (preg_match('/^[a-zA-Z0-9_\\-\\.]*$/', $file['name'])) {
             // No need to fix ASCII.
             $name = fix_utf8($name);
         } else {
             if (!($file['general'] & pow(2, 11))) {
                 // First look for unicode name alternatives.
                 $found = false;
                 foreach ($file['extra'] as $extra) {
                     if ($extra['id'] === 0x7075) {
                         $data = unpack('cversion/Vcrc', substr($extra['data'], 0, 5));
                         if ($data['crc'] === crc32($name)) {
                             $found = true;
                             $name = substr($extra['data'], 5);
                         }
                     }
                 }
                 if (!$found and !empty($this->encoding) and $this->encoding !== 'utf-8') {
                     // Try the encoding from open().
                     $newname = @core_text::convert($name, $this->encoding, 'utf-8');
                     $original = core_text::convert($newname, 'utf-8', $this->encoding);
                     if ($original === $name) {
                         $found = true;
                         $name = $newname;
                     }
                 }
                 if (!$found and $file['version'] === 0x315) {
                     // This looks like OS X build in zipper.
                     $newname = fix_utf8($name);
                     if ($newname === $name) {
                         $found = true;
                         $name = $newname;
                     }
                 }
                 if (!$found and $file['version'] === 0) {
                     // This looks like our old borked Moodle 2.2 file.
                     $newname = fix_utf8($name);
                     if ($newname === $name) {
                         $found = true;
                         $name = $newname;
                     }
                 }
                 if (!$found and $encoding = get_string('oldcharset', 'langconfig')) {
                     // Last attempt - try the dos/unix encoding from current language.
                     $windows = true;
                     foreach ($file['extra'] as $extra) {
                         // In Windows archivers do not usually set any extras with the exception of NTFS flag in WinZip/WinRar.
                         $windows = false;
                         if ($extra['id'] === 0xa) {
//.........这里部分代码省略.........
开发者ID:Keneth1212,项目名称:moodle,代码行数:101,代码来源:zip_archive.php

示例7: load_csv_content

 /**
  * Parse this content
  *
  * @global object
  * @global object
  * @param string $content passed by ref for memory reasons, unset after return
  * @param string $encoding content encoding
  * @param string $delimiter_name separator (comma, semicolon, colon, cfg)
  * @param string $column_validation name of function for columns validation, must have one param $columns
  * @param string $enclosure field wrapper. One character only.
  * @return bool false if error, count of data lines if ok; use get_error() to get error string
  */
 function load_csv_content(&$content, $encoding, $delimiter_name, $column_validation = null, $enclosure = '"')
 {
     global $USER, $CFG;
     $this->close();
     $this->_error = null;
     $content = core_text::convert($content, $encoding, 'utf-8');
     // remove Unicode BOM from first line
     $content = core_text::trim_utf8_bom($content);
     // Fix mac/dos newlines
     $content = preg_replace('!\\r\\n?!', "\n", $content);
     // Remove any spaces or new lines at the end of the file.
     if ($delimiter_name == 'tab') {
         // trim() by default removes tabs from the end of content which is undesirable in a tab separated file.
         $content = trim($content, chr(0x20) . chr(0xa) . chr(0xd) . chr(0x0) . chr(0xb));
     } else {
         $content = trim($content);
     }
     $csv_delimiter = csv_import_reader::get_delimiter($delimiter_name);
     // $csv_encode    = csv_import_reader::get_encoded_delimiter($delimiter_name);
     // Create a temporary file and store the csv file there,
     // do not try using fgetcsv() because there is nothing
     // to split rows properly - fgetcsv() itself can not do it.
     $tempfile = tempnam(make_temp_directory('/csvimport'), 'tmp');
     if (!($fp = fopen($tempfile, 'w+b'))) {
         $this->_error = get_string('cannotsavedata', 'error');
         @unlink($tempfile);
         return false;
     }
     fwrite($fp, $content);
     fseek($fp, 0);
     // Create an array to store the imported data for error checking.
     $columns = array();
     // str_getcsv doesn't iterate through the csv data properly. It has
     // problems with line returns.
     while ($fgetdata = fgetcsv($fp, 0, $csv_delimiter, $enclosure)) {
         // Check to see if we have an empty line.
         if (count($fgetdata) == 1) {
             if ($fgetdata[0] !== null) {
                 // The element has data. Add it to the array.
                 $columns[] = $fgetdata;
             }
         } else {
             $columns[] = $fgetdata;
         }
     }
     $col_count = 0;
     // process header - list of columns
     if (!isset($columns[0])) {
         $this->_error = get_string('csvemptyfile', 'error');
         fclose($fp);
         unlink($tempfile);
         return false;
     } else {
         $col_count = count($columns[0]);
     }
     // Column validation.
     if ($column_validation) {
         $result = $column_validation($columns[0]);
         if ($result !== true) {
             $this->_error = $result;
             fclose($fp);
             unlink($tempfile);
             return false;
         }
     }
     $this->_columns = $columns[0];
     // cached columns
     // check to make sure that the data columns match up with the headers.
     foreach ($columns as $rowdata) {
         if (count($rowdata) !== $col_count) {
             $this->_error = get_string('csvweirdcolumns', 'error');
             fclose($fp);
             unlink($tempfile);
             $this->cleanup();
             return false;
         }
     }
     $filename = $CFG->tempdir . '/csvimport/' . $this->_type . '/' . $USER->id . '/' . $this->_iid;
     $filepointer = fopen($filename, "w");
     // The information has been stored in csv format, as serialized data has issues
     // with special characters and line returns.
     $storedata = csv_export_writer::print_array($columns, ',', '"', true);
     fwrite($filepointer, $storedata);
     fclose($fp);
     unlink($tempfile);
     fclose($filepointer);
     $datacount = count($columns);
     return $datacount;
//.........这里部分代码省略.........
开发者ID:abhilash1994,项目名称:moodle,代码行数:101,代码来源:csvlib.class.php

示例8: ntlmsso_magic

 /**
  * To be called from a page running under NTLM's
  * "Integrated Windows Authentication".
  *
  * If successful, it will set a special "cookie" (not an HTTP cookie!)
  * in cache_flags under the $this->pluginconfig/ntlmsess "plugin" and return true.
  * The "cookie" will be picked up by ntlmsso_finish() to complete the
  * process.
  *
  * On failure it will return false for the caller to display an appropriate
  * error message (probably saying that Integrated Windows Auth isn't enabled!)
  *
  * NOTE that this code will execute under the OS user credentials,
  * so we MUST avoid dealing with files -- such as session files.
  * (The caller should define('NO_MOODLE_COOKIES', true) before including config.php)
  *
  */
 function ntlmsso_magic($sesskey)
 {
     if (isset($_SERVER['REMOTE_USER']) && !empty($_SERVER['REMOTE_USER'])) {
         // HTTP __headers__ seem to be sent in ISO-8859-1 encoding
         // (according to my reading of RFC-1945, RFC-2616 and RFC-2617 and
         // my local tests), so we need to convert the REMOTE_USER value
         // (i.e., what we got from the HTTP WWW-Authenticate header) into UTF-8
         $username = core_text::convert($_SERVER['REMOTE_USER'], 'iso-8859-1', 'utf-8');
         switch ($this->config->ntlmsso_type) {
             case 'ntlm':
                 // The format is now configurable, so try to extract the username
                 $username = $this->get_ntlm_remote_user($username);
                 if (empty($username)) {
                     return false;
                 }
                 break;
             case 'kerberos':
                 // Format is username@DOMAIN
                 $username = substr($username, 0, strpos($username, '@'));
                 break;
             default:
                 error_log($this->errorlogtag . get_string('ntlmsso_unknowntype', 'auth_ldap'));
                 return false;
                 // Should never happen!
         }
         $username = core_text::strtolower($username);
         // Compatibility hack
         set_cache_flag($this->pluginconfig . '/ntlmsess', $sesskey, $username, AUTH_NTLMTIMEOUT);
         return true;
     }
     return false;
 }
开发者ID:jeffthestampede,项目名称:excelsior,代码行数:49,代码来源:auth.php

示例9: email_to_user


//.........这里部分代码省略.........
    }
    $mail->Subject = substr($subject, 0, 900);
    $temprecipients[] = array($user->email, fullname($user));
    // Set word wrap.
    $mail->WordWrap = $wordwrapwidth;
    if (!empty($from->customheaders)) {
        // Add custom headers.
        if (is_array($from->customheaders)) {
            foreach ($from->customheaders as $customheader) {
                $mail->addCustomHeader($customheader);
            }
        } else {
            $mail->addCustomHeader($from->customheaders);
        }
    }
    if (!empty($from->priority)) {
        $mail->Priority = $from->priority;
    }
    if ($messagehtml && !empty($user->mailformat) && $user->mailformat == 1) {
        // Don't ever send HTML to users who don't want it.
        $mail->isHTML(true);
        $mail->Encoding = 'quoted-printable';
        $mail->Body = $messagehtml;
        $mail->AltBody = "\n{$messagetext}\n";
    } else {
        $mail->IsHTML(false);
        $mail->Body = "\n{$messagetext}\n";
    }
    if ($attachment && $attachname) {
        if (preg_match("~\\.\\.~", $attachment)) {
            // Security check for ".." in dir path.
            $temprecipients[] = array($supportuser->email, fullname($supportuser, true));
            $mail->addStringAttachment('Error in attachment.  User attempted to attach a filename with a unsafe name.', 'error.txt', '8bit', 'text/plain');
        } else {
            require_once $CFG->libdir . '/filelib.php';
            $mimetype = mimeinfo('type', $attachname);
            $attachmentpath = $attachment;
            // Before doing the comparison, make sure that the paths are correct (Windows uses slashes in the other direction).
            $attachpath = str_replace('\\', '/', $attachmentpath);
            // Make sure both variables are normalised before comparing.
            $temppath = str_replace('\\', '/', $CFG->tempdir);
            // If the attachment is a full path to a file in the tempdir, use it as is,
            // otherwise assume it is a relative path from the dataroot (for backwards compatibility reasons).
            if (strpos($attachpath, realpath($temppath)) !== 0) {
                $attachmentpath = $CFG->dataroot . '/' . $attachmentpath;
            }
            $mail->addAttachment($attachmentpath, $attachname, 'base64', $mimetype);
        }
    }
    // Check if the email should be sent in an other charset then the default UTF-8.
    if (!empty($CFG->sitemailcharset) || !empty($CFG->allowusermailcharset)) {
        // Use the defined site mail charset or eventually the one preferred by the recipient.
        $charset = $CFG->sitemailcharset;
        if (!empty($CFG->allowusermailcharset)) {
            if ($useremailcharset = get_user_preferences('mailcharset', '0', $user->id)) {
                $charset = $useremailcharset;
            }
        }
        // Convert all the necessary strings if the charset is supported.
        $charsets = get_list_of_charsets();
        unset($charsets['UTF-8']);
        if (in_array($charset, $charsets)) {
            $mail->CharSet = $charset;
            $mail->FromName = core_text::convert($mail->FromName, 'utf-8', strtolower($charset));
            $mail->Subject = core_text::convert($mail->Subject, 'utf-8', strtolower($charset));
            $mail->Body = core_text::convert($mail->Body, 'utf-8', strtolower($charset));
            $mail->AltBody = core_text::convert($mail->AltBody, 'utf-8', strtolower($charset));
            foreach ($temprecipients as $key => $values) {
                $temprecipients[$key][1] = core_text::convert($values[1], 'utf-8', strtolower($charset));
            }
            foreach ($tempreplyto as $key => $values) {
                $tempreplyto[$key][1] = core_text::convert($values[1], 'utf-8', strtolower($charset));
            }
        }
    }
    foreach ($temprecipients as $values) {
        $mail->addAddress($values[0], $values[1]);
    }
    foreach ($tempreplyto as $values) {
        $mail->addReplyTo($values[0], $values[1]);
    }
    if ($mail->send()) {
        set_send_count($user);
        if (!empty($mail->SMTPDebug)) {
            echo '</pre>';
        }
        return true;
    } else {
        // Trigger event for failing to send email.
        $event = \core\event\email_failed::create(array('context' => context_system::instance(), 'userid' => $from->id, 'relateduserid' => $user->id, 'other' => array('subject' => $subject, 'message' => $messagetext, 'errorinfo' => $mail->ErrorInfo)));
        $event->trigger();
        if (CLI_SCRIPT) {
            mtrace('Error: lib/moodlelib.php email_to_user(): ' . $mail->ErrorInfo);
        }
        if (!empty($mail->SMTPDebug)) {
            echo '</pre>';
        }
        return false;
    }
}
开发者ID:riawarra,项目名称:moodle,代码行数:101,代码来源:moodlelib.php

示例10: user_update

 /**
  * Called when the user record is updated.
  * Modifies user in external database. It takes olduser (before changes) and newuser (after changes)
  * compares information saved modified information to external db.
  *
  * @param stdClass $olduser     Userobject before modifications
  * @param stdClass $newuser     Userobject new modified userobject
  * @return boolean result
  *
  */
 function user_update($olduser, $newuser)
 {
     if (isset($olduser->username) and isset($newuser->username) and $olduser->username != $newuser->username) {
         error_log("ERROR:User renaming not allowed in ext db");
         return false;
     }
     if (isset($olduser->auth) and $olduser->auth != $this->authtype) {
         return true;
         // Just change auth and skip update.
     }
     $curruser = $this->get_userinfo($olduser->username);
     if (empty($curruser)) {
         error_log("ERROR:User {$olduser->username} found in ext db");
         return false;
     }
     $extusername = core_text::convert($olduser->username, 'utf-8', $this->config->extencoding);
     $authdb = $this->db_init();
     $update = array();
     foreach ($curruser as $key => $value) {
         if ($key == 'username') {
             continue;
             // Skip this.
         }
         if (empty($this->config->{"field_updateremote_{$key}"})) {
             continue;
             // Remote update not requested.
         }
         if (!isset($newuser->{$key})) {
             continue;
         }
         $nuvalue = $newuser->{$key};
         if ($nuvalue != $value) {
             $update[] = $this->config->{"field_map_{$key}"} . "='" . $this->ext_addslashes(core_text::convert($nuvalue, 'utf-8', $this->config->extencoding)) . "'";
         }
     }
     if (!empty($update)) {
         $authdb->Execute("UPDATE {$this->config->table}\n                                 SET " . implode(',', $update) . "\n                               WHERE {$this->config->fielduser}='" . $this->ext_addslashes($extusername) . "'");
     }
     $authdb->Close();
     return true;
 }
开发者ID:janaece,项目名称:globalclassroom4_clean,代码行数:51,代码来源:auth.php

示例11: feedback_check_xml_utf8

function feedback_check_xml_utf8($text)
{
    //find the encoding
    $searchpattern = '/^\\<\\?xml.+(encoding=\\"([a-z0-9-]*)\\").+\\?\\>/is';
    if (!preg_match($searchpattern, $text, $match)) {
        return false;
        //no xml-file
    }
    //$match[0] = \<\? xml ... \?\> (without \)
    //$match[1] = encoding="...."
    //$match[2] = ISO-8859-1 or so on
    if (isset($match[0]) and !isset($match[1])) {
        //no encoding given. we assume utf-8
        return $text;
    }
    //encoding is given in $match[2]
    if (isset($match[0]) and isset($match[1]) and isset($match[2])) {
        $enc = $match[2];
        return core_text::convert($text, $enc);
    }
}
开发者ID:EmmanuelYupit,项目名称:educursos,代码行数:21,代码来源:import.php

示例12: unmangle_pathname

 /**
  * Tries to convert $localname into utf-8
  * please note that it may fail really badly.
  * The resulting file name is cleaned.
  *
  * @param string $localname name of file in $this->encoding
  * @return string in utf-8
  */
 protected function unmangle_pathname($localname)
 {
     $result = str_replace('\\', '/', $localname);
     // no MS \ separators
     $result = ltrim($result, '/');
     // no leading /
     if ($this->encoding !== 'utf-8') {
         $result = core_text::convert($result, $this->encoding, 'utf-8');
     }
     return clean_param($result, PARAM_PATH);
 }
开发者ID:pzhu2004,项目名称:moodle,代码行数:19,代码来源:file_archive.php

示例13: test_strtoupper

 /**
  * Tests the static strtoupper.
  */
 public function test_strtoupper()
 {
     $str = "Žluťoučký koníček";
     $up = 'ŽLUŤOUČKÝ KONÍČEK';
     $this->assertSame($up, core_text::strtoupper($str));
     $iso2 = pack("H*", "ae6c75bb6f75e86bfd206b6f6eede8656b");
     $this->assertSame(core_text::convert($up, 'utf-8', 'iso-8859-2'), core_text::strtoupper($iso2, 'iso-8859-2'));
     $win = pack("H*", "8e6c759d6f75e86bfd206b6f6eede8656b");
     $this->assertSame(core_text::convert($up, 'utf-8', 'cp1250'), core_text::strtoupper($win, 'cp1250'));
     $str = '言語設定';
     $this->assertSame($str, core_text::strtoupper($str));
     $str = '简体中文';
     $this->assertSame($str, core_text::strtoupper($str));
     $str = pack("H*", "1b24423840386c405f446a1b2842");
     // ISO-2022-JP
     $this->assertSame($str, core_text::strtoupper($str, 'ISO-2022-JP'));
     $str = pack("H*", "8cbe8cea90dd92e8");
     // SHIFT-JIS
     $this->assertSame($str, core_text::strtoupper($str, 'SHIFT-JIS'));
     $str = pack("H*", "bcf2cce5d6d0cec4");
     // GB2312
     $this->assertSame($str, core_text::strtoupper($str, 'GB2312'));
     $str = pack("H*", "bcf2cce5d6d0cec4");
     // GB18030
     $this->assertSame($str, core_text::strtoupper($str, 'GB18030'));
 }
开发者ID:rushi963,项目名称:moodle,代码行数:29,代码来源:text_test.php

示例14: textlib

     print_error('nomanualenrol', 'local_ltiprovider');
 }
 // Transform to utf8 all the post and get data
 if (class_exists('textlib')) {
     $textlib = new textlib();
 } else {
     try {
         // for older moodle instances
         $textlib = textlib_get_instance();
     } catch (Exception $e) {
         // updated to use new core_text lib as required by Moodle 2.9
         $textlib = new core_text();
     }
 }
 foreach ($_POST as $key => $value) {
     $_POST[$key] = $textlib->convert($value, $tool->encoding);
 }
 foreach ($_GET as $key => $value) {
     $_GET[$key] = $textlib->convert($value, $tool->encoding);
 }
 // We need an username without extended chars
 // Later accounts add the ConsumerKey - we silently upgrade old accounts
 // Might want a flag for this -- Chuck
 $username = local_ltiprovider_create_username($context->info['oauth_consumer_key'], $context->info['user_id']);
 $dbuser = $DB->get_record('user', array('username' => $username));
 if (!$dbuser) {
     $old_username = 'ltiprovider' . md5($context->getUserKey());
     $dbuser = $DB->get_record('user', array('username' => $old_username));
     if ($dbuser) {
         // Probably should log this
         $DB->set_field('user', 'username', $username, array('id' => $dbuser->id));
开发者ID:jellisii,项目名称:moodle-local_ltiprovider,代码行数:31,代码来源:tool.php

示例15: local_ent_installer_get_userinfo

/**
 * Reads user information from ldap and returns it in array()
 *
 * Function should return all information available. If you are saving
 * this information to moodle user-table you should honor syncronization flags
 *
 * @param object $ldapauth the ldap authentication instance
 * @param string $username username
 * @param array $options an array with CLI input options
 *
 * @return mixed array with no magic quotes or false on error
 */
function local_ent_installer_get_userinfo($ldapauth, $username, $options = array())
{
    static $entattributes;
    // Load some cached static data.
    if (!isset($entattributes)) {
        // aggregate additional ent specific attributes that hold interesting information
        $configattribs = get_config('local_ent_installer', 'ent_userinfo_attributes');
        if (empty($configattribs)) {
            $entattributes = array('ENTPersonFonctions', 'ENTPersonJointure', 'ENTEleveClasses', 'ENTEleveGroupes', 'ENTEleveTransport', 'ENTEleveRegime', 'ENTPersonProfils', 'objectGUID');
        } else {
            $entattributes = explode(',', $configattribs);
        }
    }
    $extusername = core_text::convert($username, 'utf-8', $ldapauth->config->ldapencoding);
    $ldapconnection = $ldapauth->ldap_connect();
    if (!($user_dn = $ldapauth->ldap_find_userdn($ldapconnection, $extusername))) {
        $ldapauth->ldap_close();
        return false;
    }
    $search_attribs = array();
    $attrmap = $ldapauth->ldap_attributes();
    foreach ($attrmap as $key => $values) {
        if (!is_array($values)) {
            $values = array($values);
        }
        foreach ($values as $value) {
            if (!in_array($value, $search_attribs)) {
                array_push($search_attribs, $value);
            }
        }
    }
    foreach ($entattributes as $value) {
        if (!in_array($value, $search_attribs)) {
            array_push($search_attribs, $value);
            // Add attributes to $attrmap so they are pulled down into final user object.
            $attrmap[$value] = strtolower($value);
        }
    }
    if ($options['verbose']) {
        mtrace("Getting {$user_dn} for " . implode(',', $search_attribs));
    }
    if (!($user_info_result = ldap_read($ldapconnection, $user_dn, '(objectClass=*)', $search_attribs))) {
        $ldapauth->ldap_close();
        return false;
    }
    $user_entry = ldap_get_entries_moodle($ldapconnection, $user_info_result);
    if (empty($user_entry)) {
        $ldapauth->ldap_close();
        return false;
        // Entry not found.
    }
    $result = array();
    foreach ($attrmap as $key => $values) {
        if (!is_array($values)) {
            $values = array($values);
        }
        $ldapval = NULL;
        foreach ($values as $value) {
            $entry = array_change_key_case($user_entry[0], CASE_LOWER);
            if ($value == 'dn' || $value == 'distinguishedname') {
                $result[$key] = $user_dn;
                continue;
            }
            if (!array_key_exists($value, $entry)) {
                if ($options['verbose']) {
                    mtrace("Requested value {$value} but missing in record");
                }
                continue;
                // wrong data mapping!
            }
            if ($value == 'objectguid') {
                if (strlen($entry[$value][0]) == 16) {
                    $tmp = bin2hex($entry[$value][0]);
                    $t = $tmp[6] . $tmp[7] . $tmp[4] . $tmp[5] . $tmp[2] . $tmp[3] . $tmp[0] . $tmp[1] . '-';
                    $t .= $tmp[10] . $tmp[11] . $tmp[8] . $tmp[9] . '-';
                    $t .= $tmp[14] . $tmp[15] . $tmp[12] . $tmp[13] . '-';
                    $t .= substr($tmp, 16, 4) . '-';
                    $t .= substr($tmp, 20);
                    $objectguid = $t;
                }
                $newval = $objectguid;
            } else {
                if ($value == 'entelevegroupes' && is_array($entry[$value])) {
                    $newval = array();
                    foreach ($entry[$value] as $subkey => $subvalue) {
                        if ($subkey !== 'count') {
                            $newval[] = core_text::convert($subvalue, $ldapauth->config->ldapencoding, 'utf-8');
                        }
//.........这里部分代码省略.........
开发者ID:OctaveBabel,项目名称:moodle-itop,代码行数:101,代码来源:ldaplib.php


注:本文中的core_text::convert方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。