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


PHP textlib::convert方法代码示例

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


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

示例1: 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

示例2: sanitize

 public function sanitize($data, $type, $base = '')
 {
     $data = trim($data);
     if ($data === '') {
         return '';
     }
     if ($type & SIMPLEPIE_CONSTRUCT_BASE64) {
         $data = base64_decode($data);
     }
     if ($type & SIMPLEPIE_CONSTRUCT_MAYBE_HTML) {
         if (preg_match('/(&(#(x[0-9a-fA-F]+|[0-9]+)|[a-zA-Z0-9]+)|<\\/[A-Za-z][^\\x09\\x0A\\x0B\\x0C\\x0D\\x20\\x2F\\x3E]*' . SIMPLEPIE_PCRE_HTML_ATTRIBUTE . '>)/', $data)) {
             $type |= SIMPLEPIE_CONSTRUCT_HTML;
         } else {
             $type |= SIMPLEPIE_CONSTRUCT_TEXT;
         }
     }
     if ($type & SIMPLEPIE_CONSTRUCT_IRI) {
         $absolute = $this->registry->call('Misc', 'absolutize_url', array($data, $base));
         if ($absolute !== false) {
             $data = $absolute;
         }
         $data = clean_param($data, PARAM_URL);
     }
     if ($type & (SIMPLEPIE_CONSTRUCT_TEXT | SIMPLEPIE_CONSTRUCT_IRI)) {
         $data = htmlspecialchars($data, ENT_COMPAT, 'UTF-8');
     }
     $data = purify_html($data);
     if ($this->remove_div) {
         $data = preg_replace('/^<div' . SIMPLEPIE_PCRE_XML_ATTRIBUTE . '>/', '', $data);
         $data = preg_replace('/<\\/div>$/', '', $data);
     } else {
         $data = preg_replace('/^<div' . SIMPLEPIE_PCRE_XML_ATTRIBUTE . '>/', '<div>', $data);
     }
     if ($this->output_encoding !== 'UTF-8') {
         textlib::convert($data, 'UTF-8', $this->output_encoding);
     }
     return $data;
 }
开发者ID:masaterutakeno,项目名称:MoodleMobile,代码行数:38,代码来源:moodle_simplepie.php

示例3: 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->geoipfile) and file_exists($CFG->geoipfile)) {
        require_once 'Net/GeoIP.php';
        $geoip = Net_GeoIP::getInstance($CFG->geoipfile, Net_GeoIP::STANDARD);
        $location = $geoip->lookupLocation($ip);
        $geoip->close();
        if (empty($location)) {
            $info['error'] = get_string('iplookupfailed', 'error', $ip);
            return $info;
        }
        if (!empty($location->city)) {
            $info['city'] = textlib::convert($location->city, 'iso-8859-1', 'utf-8');
            $info['title'][] = $info['city'];
        }
        if (!empty($location->country_code)) {
            $countries = get_string_manager()->get_list_of_countries(true);
            if (isset($countries[$location->country_code])) {
                // prefer our localized country names
                $info['country'] = $countries[$location->country_code];
            } else {
                $info['country'] = $location->country_name;
            }
            $info['title'][] = $info['country'];
        }
        $info['longitude'] = $location->longitude;
        $info['latitude'] = $location->latitude;
        $info['note'] = get_string('iplookupmaxmindnote', 'admin');
        return $info;
    } else {
        require_once $CFG->libdir . '/filelib.php';
        $ipdata = download_file_content('http://netgeo.caida.org/perl/netgeo.cgi?target=' . $ip);
        if ($ipdata === false) {
            $info['error'] = get_string('cannotnetgeo', 'error');
            return $info;
        }
        $matches = null;
        if (!preg_match('/LAT:\\s*(-?\\d+\\.\\d+)/s', $ipdata, $matches)) {
            $info['error'] = get_string('iplookupfailed', 'error', $ip);
            return $info;
        }
        $info['latitude'] = (double) $matches[1];
        if (!preg_match('/LONG:\\s*(-?\\d+\\.\\d+)/s', $ipdata, $matches)) {
            $info['error'] = get_string('iplookupfailed', 'error', $ip);
            return $info;
        }
        $info['longitude'] = (double) $matches[1];
        if (preg_match('/CITY:\\s*([^<]*)/', $ipdata, $matches)) {
            if (!empty($matches[1])) {
                $info['city'] = s($matches[1]);
                $info['title'][] = $info['city'];
            }
        }
        if (preg_match('/COUNTRY:\\s*([^<]*)/', $ipdata, $matches)) {
            if (!empty($matches[1])) {
                $countrycode = $matches[1];
                $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'] = $countrycode;
                }
                $info['title'][] = $info['country'];
            }
        }
        $info['note'] = get_string('iplookupnetgeonote', 'admin');
        return $info;
    }
}
开发者ID:numbas,项目名称:moodle,代码行数:77,代码来源:lib.php

示例4: if

    } else if ($type === 'file') {
        // Large files are likely to take their time and memory. Let PHP know
        // that we'll take longer, and that the process should be recycled soon
        // to free up memory.
        @set_time_limit(0);
        @raise_memory_limit("192M");
        if (function_exists('apache_child_terminate')) {
            @apache_child_terminate();
        }

        $text = $form->get_file_content('userfile');

        // Trim utf-8 bom.
        $text = textlib::trim_utf8_bom($text);
        // Do the encoding conversion.
        $rawinput = textlib::convert($text, $data->encoding);
    }

    // Replace commas with newlines and remove carriage returns.
    $rawinput = str_replace(array("\r\n", "\r", ","), "\n", $rawinput);

    $addusers = clean_param($rawinput, PARAM_NOTAGS);
    // Turn into array.
    $addusers = explode("\n", $addusers);
    // Remove any leading or trailing spaces.
    $addusers = array_map('trim', $addusers);
    // Filter out empty strings/false/null using array_filter.
    $addusers = array_filter($addusers);

    // Bulk add results
    $errors = array();
开发者ID:narasimhaeabyas,项目名称:tataaiapro,代码行数:31,代码来源:bulkadd_attendees.php

示例5: iscreator

 /**
  * Returns true if user should be coursecreator.
  *
  * @param mixed $username    username (without system magic quotes)
  * @return boolean result
  */
 function iscreator($username)
 {
     if (empty($this->config->host_url) or empty($this->config->attrcreators) && empty($this->config->groupecreators) or empty($this->config->memberattribute)) {
         return false;
     }
     $extusername = textlib::convert($username, 'utf-8', $this->config->ldapencoding);
     // Test for group creator
     if (!empty($this->config->groupecreators)) {
         $ldapconnection = $this->ldap_connect();
         if ($this->config->memberattribute_isdn) {
             if (!($userid = $this->ldap_find_userdn($ldapconnection, $extusername))) {
                 return false;
             }
         } else {
             $userid = $extusername;
         }
         $group_dns = explode(';', $this->config->groupecreators);
         if (ldap_isgroupmember($ldapconnection, $userid, $group_dns, $this->config->memberattribute)) {
             return true;
         }
     }
     // Build filter for attrcreator
     if (!empty($this->config->attrcreators)) {
         $attrs = explode(';', $this->config->attrcreators);
         $filter = '(& (' . $this->config->user_attribute . "={$username})(|";
         foreach ($attrs as $attr) {
             if (strpos($attr, '=')) {
                 $filter .= "({$attr})";
             } else {
                 $filter .= '(' . $this->config->memberattribute . "={$attr})";
             }
         }
         $filter .= '))';
         // Search
         $result = $this->ldap_get_userlist($filter);
         if (count($result) != 0) {
             return true;
         }
     }
     return false;
 }
开发者ID:verbazend,项目名称:AWFA,代码行数:47,代码来源:auth.php

示例6: 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
  * @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)
 {
     global $USER, $CFG;
     $this->close();
     $this->_error = null;
     $content = textlib::convert($content, $encoding, 'utf-8');
     // remove Unicode BOM from first line
     $content = textlib::trim_utf8_bom($content);
     // Fix mac/dos newlines
     $content = preg_replace('!\\r\\n?!', "\n", $content);
     // is there anyting in file?
     $columns = strtok($content, "\n");
     if ($columns === false) {
         $this->_error = get_string('csvemptyfile', 'error');
         return false;
     }
     $csv_delimiter = csv_import_reader::get_delimiter($delimiter_name);
     $csv_encode = csv_import_reader::get_encoded_delimiter($delimiter_name);
     // process header - list of columns
     $columns = explode($csv_delimiter, $columns);
     $col_count = count($columns);
     if ($col_count === 0) {
         $this->_error = get_string('csvemptyfile', 'error');
         return false;
     }
     foreach ($columns as $key => $value) {
         $columns[$key] = str_replace($csv_encode, $csv_delimiter, trim($value));
     }
     if ($column_validation) {
         $result = $column_validation($columns);
         if ($result !== true) {
             $this->_error = $result;
             return false;
         }
     }
     $this->_columns = $columns;
     // cached columns
     // open file for writing
     $filename = $CFG->tempdir . '/csvimport/' . $this->_type . '/' . $USER->id . '/' . $this->_iid;
     $fp = fopen($filename, "w");
     fwrite($fp, serialize($columns) . "\n");
     // again - do we have any data for processing?
     $line = strtok("\n");
     $data_count = 0;
     while ($line !== false) {
         $line = explode($csv_delimiter, $line);
         foreach ($line as $key => $value) {
             $line[$key] = str_replace($csv_encode, $csv_delimiter, trim($value));
         }
         if (count($line) !== $col_count) {
             // this is critical!!
             $this->_error = get_string('csvweirdcolumns', 'error');
             fclose($fp);
             $this->cleanup();
             return false;
         }
         fwrite($fp, serialize($line) . "\n");
         $data_count++;
         $line = strtok("\n");
     }
     fclose($fp);
     return $data_count;
 }
开发者ID:saurabh947,项目名称:MoodleLearning,代码行数:74,代码来源:csvlib.class.php

示例7: find_ext_enrolments

 /**
  * Return multidimensional array with details of user courses (at
  * least dn and idnumber).
  *
  * @param string $memberuid user idnumber (without magic quotes).
  * @param object role is a record from the mdl_role table.
  * @return array
  */
 protected function find_ext_enrolments($memberuid, $role)
 {
     global $CFG;
     require_once $CFG->libdir . '/ldaplib.php';
     if (empty($memberuid)) {
         // No "idnumber" stored for this user, so no LDAP enrolments
         return array();
     }
     $ldap_contexts = trim($this->get_config('contexts_role' . $role->id));
     if (empty($ldap_contexts)) {
         // No role contexts, so no LDAP enrolments
         return array();
     }
     $extmemberuid = textlib::convert($memberuid, 'utf-8', $this->get_config('ldapencoding'));
     if ($this->get_config('memberattribute_isdn')) {
         if (!($extmemberuid = $this->ldap_find_userdn($extmemberuid))) {
             return array();
         }
     }
     $ldap_search_pattern = '';
     if ($this->get_config('nested_groups')) {
         $usergroups = $this->ldap_find_user_groups($extmemberuid);
         if (count($usergroups) > 0) {
             foreach ($usergroups as $group) {
                 $ldap_search_pattern .= '(' . $this->get_config('memberattribute_role' . $role->id) . '=' . $group . ')';
             }
         }
     }
     // Default return value
     $courses = array();
     // Get all the fields we will want for the potential course creation
     // as they are light. don't get membership -- potentially a lot of data.
     $ldap_fields_wanted = array('dn', $this->get_config('course_idnumber'));
     $fullname = $this->get_config('course_fullname');
     $shortname = $this->get_config('course_shortname');
     $summary = $this->get_config('course_summary');
     if (isset($fullname)) {
         array_push($ldap_fields_wanted, $fullname);
     }
     if (isset($shortname)) {
         array_push($ldap_fields_wanted, $shortname);
     }
     if (isset($summary)) {
         array_push($ldap_fields_wanted, $summary);
     }
     // Define the search pattern
     if (empty($ldap_search_pattern)) {
         $ldap_search_pattern = '(' . $this->get_config('memberattribute_role' . $role->id) . '=' . ldap_filter_addslashes($extmemberuid) . ')';
     } else {
         $ldap_search_pattern = '(|' . $ldap_search_pattern . '(' . $this->get_config('memberattribute_role' . $role->id) . '=' . ldap_filter_addslashes($extmemberuid) . ')' . ')';
     }
     $ldap_search_pattern = '(&' . $this->get_config('objectclass') . $ldap_search_pattern . ')';
     // Get all contexts and look for first matching user
     $ldap_contexts = explode(';', $ldap_contexts);
     $ldap_pagedresults = ldap_paged_results_supported($this->get_config('ldap_version'));
     foreach ($ldap_contexts as $context) {
         $context = trim($context);
         if (empty($context)) {
             continue;
         }
         $ldap_cookie = '';
         $flat_records = array();
         do {
             if ($ldap_pagedresults) {
                 ldap_control_paged_result($this->ldapconnection, $this->config->pagesize, true, $ldap_cookie);
             }
             if ($this->get_config('course_search_sub')) {
                 // Use ldap_search to find first user from subtree
                 $ldap_result = @ldap_search($this->ldapconnection, $context, $ldap_search_pattern, $ldap_fields_wanted);
             } else {
                 // Search only in this context
                 $ldap_result = @ldap_list($this->ldapconnection, $context, $ldap_search_pattern, $ldap_fields_wanted);
             }
             if (!$ldap_result) {
                 continue;
             }
             if ($ldap_pagedresults) {
                 ldap_control_paged_result_response($this->ldapconnection, $ldap_result, $ldap_cookie);
             }
             // Check and push results. ldap_get_entries() already
             // lowercases the attribute index, so there's no need to
             // use array_change_key_case() later.
             $records = ldap_get_entries($this->ldapconnection, $ldap_result);
             // LDAP libraries return an odd array, really. Fix it.
             for ($c = 0; $c < $records['count']; $c++) {
                 array_push($flat_records, $records[$c]);
             }
             // Free some mem
             unset($records);
         } while ($ldap_pagedresults && !empty($ldap_cookie));
         // If LDAP paged results were used, the current connection must be completely
         // closed and a new one created, to work without paged results from here on.
//.........这里部分代码省略.........
开发者ID:Jtgadbois,项目名称:Pedadida,代码行数:101,代码来源:lib.php

示例8: email_to_user


//.........这里部分代码省略.........
            $mail->From = $CFG->noreplyaddress;
            $mail->FromName = fullname($from);
            if (empty($replyto)) {
                $tempreplyto[] = array($CFG->noreplyaddress, get_string('noreplyname'));
            }
        }
    }
    if (!empty($replyto)) {
        $tempreplyto[] = array($replyto, $replytoname);
    }
    $mail->Subject = substr($subject, 0, 900);
    $temprecipients[] = array($user->email, fullname($user));
    $mail->WordWrap = $wordwrapwidth;
    // set word wrap
    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';
        // Encoding to use
        $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);
            $mail->AddAttachment($CFG->dataroot . '/' . $attachment, $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 = textlib::convert($mail->FromName, 'utf-8', strtolower($charset));
            $mail->Subject = textlib::convert($mail->Subject, 'utf-8', strtolower($charset));
            $mail->Body = textlib::convert($mail->Body, 'utf-8', strtolower($charset));
            $mail->AltBody = textlib::convert($mail->AltBody, 'utf-8', strtolower($charset));
            foreach ($temprecipients as $key => $values) {
                $temprecipients[$key][1] = textlib::convert($values[1], 'utf-8', strtolower($charset));
            }
            foreach ($tempreplyto as $key => $values) {
                $tempreplyto[$key][1] = textlib::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);
        $mail->IsSMTP();
        // use SMTP directly
        if (!empty($mail->SMTPDebug)) {
            echo '</pre>';
        }
        return true;
    } else {
        add_to_log(SITEID, 'library', 'mailer', qualified_me(), 'ERROR: ' . $mail->ErrorInfo);
        if (CLI_SCRIPT) {
            mtrace('Error: lib/moodlelib.php email_to_user(): ' . $mail->ErrorInfo);
        }
        if (!empty($mail->SMTPDebug)) {
            echo '</pre>';
        }
        return false;
    }
}
开发者ID:nmicha,项目名称:moodle,代码行数:101,代码来源:moodlelib.php

示例9: grade_import_mapping_form

$mform2 = new grade_import_mapping_form(null, array('gradeitems' => $gradeitems, 'header' => $header));
// if import form is submitted
if ($formdata = $mform->get_data()) {
    // Large files are likely to take their time and memory. Let PHP know
    // that we'll take longer, and that the process should be recycled soon
    // to free up memory.
    @set_time_limit(0);
    raise_memory_limit(MEMORY_EXTRA);
    // use current (non-conflicting) time stamp
    $importcode = get_new_importcode();
    $filename = make_temp_directory('gradeimport/cvs/' . $USER->id);
    $filename = $filename . '/' . $importcode;
    $text = $mform->get_file_content('userfile');
    // trim utf-8 bom
    /// normalize line endings and do the encoding conversion
    $text = textlib::convert($text, $formdata->encoding);
    $text = textlib::trim_utf8_bom($text);
    // Fix mac/dos newlines
    $text = preg_replace('!\\r\\n?!', "\n", $text);
    $fp = fopen($filename, "w");
    fwrite($fp, $text);
    fclose($fp);
    if (!($fp = fopen($filename, "r"))) {
        print_error('cannotopenfile');
    }
    // --- get header (field names) ---
    $header = explode($csv_delimiter, fgets($fp, GRADE_CSV_LINE_LENGTH));
    // print some preview
    $numlines = 0;
    // 0 preview lines displayed
    echo $OUTPUT->heading(get_string('importpreview', 'grades'));
开发者ID:saurabh947,项目名称:MoodleLearning,代码行数:31,代码来源:index.php

示例10: get_attribute_distinct_values

 /**
  * 
  * returns the distinct values of the target LDAP attribute
  * these will be the idnumbers of the synched Moodle cohorts
  * @returns array of string 
  */
 function get_attribute_distinct_values()
 {
     //return array ('affiliate','retired','student','faculty','staff','employee','affiliate','member','alum','emeritus','researcher');
     global $CFG, $DB;
     // only these cohorts will be synched
     if (!empty($this->config->cohort_synching_ldap_attribute_idnumbers)) {
         return explode(',', $this->config->cohort_synching_ldap_attribute_idnumbers);
     }
     //build a filter to fetch all users having something in the target LDAP attribute
     $filter = '(&(' . $this->config->user_attribute . '=*)' . $this->config->objectclass . ')';
     $filter = '(&' . $filter . '(' . $this->config->cohort_synching_ldap_attribute_attribute . '=*))';
     if ($CFG->debug_ldap_groupes) {
         pp_print_object('looking for ', $filter);
     }
     $ldapconnection = $this->ldap_connect();
     $contexts = explode(';', $this->config->contexts);
     if (!empty($this->config->create_context)) {
         array_push($contexts, $this->config->create_context);
     }
     $matchings = array();
     foreach ($contexts as $context) {
         $context = trim($context);
         if (empty($context)) {
             continue;
         }
         if ($this->config->search_sub) {
             // Use ldap_search to find first user from subtree
             $ldap_result = ldap_search($ldapconnection, $context, $filter, array($this->config->cohort_synching_ldap_attribute_attribute));
         } else {
             // Search only in this context
             $ldap_result = ldap_list($ldapconnection, $context, $filter, array($this->config->cohort_synching_ldap_attribute_attribute));
         }
         if (!$ldap_result) {
             continue;
         }
         // this API function returns all attributes as an array
         // wether they are single or multiple
         $users = ldap_get_entries_moodle($ldapconnection, $ldap_result);
         // Add found DISTINCT values to list
         for ($i = 0; $i < count($users); $i++) {
             $count = $users[$i][$this->config->cohort_synching_ldap_attribute_attribute]['count'];
             for ($j = 0; $j < $count; $j++) {
                 $value = textlib::convert($users[$i][$this->config->cohort_synching_ldap_attribute_attribute][$j], $this->config->ldapencoding, 'utf-8');
                 if (!in_array($value, $matchings)) {
                     array_push($matchings, $value);
                 }
             }
         }
     }
     $this->ldap_close();
     return $matchings;
 }
开发者ID:sb-relaxt-at,项目名称:moodle_local_ldap,代码行数:58,代码来源:locallib.php

示例11: 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->geoipfile) and file_exists($CFG->geoipfile)) {
        require_once 'Net/GeoIP.php';
        $geoip = Net_GeoIP::getInstance($CFG->geoipfile, Net_GeoIP::STANDARD);
        $location = $geoip->lookupLocation($ip);
        $geoip->close();
        if (empty($location)) {
            $info['error'] = get_string('iplookupfailed', 'error', $ip);
            return $info;
        }
        if (!empty($location->city)) {
            $info['city'] = textlib::convert($location->city, 'iso-8859-1', 'utf-8');
            $info['title'][] = $info['city'];
        }
        if (!empty($location->countryCode)) {
            $countries = get_string_manager()->get_list_of_countries(true);
            if (isset($countries[$location->countryCode])) {
                // prefer our localized country names
                $info['country'] = $countries[$location->countryCode];
            } else {
                $info['country'] = $location->countryName;
            }
            $info['title'][] = $info['country'];
        } else {
            if (!empty($location->countryName)) {
                $info['country'] = $location->countryName;
                $info['title'][] = $info['country'];
            }
        }
        $info['longitude'] = $location->longitude;
        $info['latitude'] = $location->latitude;
        $info['note'] = get_string('iplookupmaxmindnote', 'admin');
        return $info;
    } else {
        require_once $CFG->libdir . '/filelib.php';
        $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:masaterutakeno,项目名称:MoodleMobile,代码行数:69,代码来源:lib.php

示例12: write_string

 /**
  * Write one string somewhere in the worksheet
  *
  * @param integer $row    Zero indexed row
  * @param integer $col    Zero indexed column
  * @param string  $str    The string to write
  * @param mixed   $format The XF format for the cell
  */
 function write_string($row, $col, $str, $format = null)
 {
     /// Calculate the internal PEAR format
     $format = $this->MoodleExcelFormat2PearExcelFormat($format);
     /// Convert the text from its original encoding to UTF-16LE
     if (!$this->latin_output) {
         /// Only if don't want to use latin (win1252) stronger output
         $str = textlib::convert($str, 'utf-8', 'utf-16le');
     } else {
         /// else, convert to latin (win1252)
         $str = textlib::convert($str, 'utf-8', 'windows-1252');
     }
     /// Add the string safely to the PEAR Worksheet
     $this->pear_excel_worksheet->writeString($row, $col, $str, $format);
 }
开发者ID:vinoth4891,项目名称:clinique,代码行数:23,代码来源:excellib.class.php

示例13: 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 = textlib::convert($result, $this->encoding, 'utf-8');
     }
     return clean_param($result, PARAM_PATH);
 }
开发者ID:masaterutakeno,项目名称:MoodleMobile,代码行数:19,代码来源:file_archive.php

示例14: 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 = textlib::convert($_SERVER['REMOTE_USER'], 'iso-8859-1', 'utf-8');
         switch ($this->config->ntlmsso_type) {
             case 'ntlm':
                 // Format is DOMAIN\username
                 $username = substr(strrchr($username, '\\'), 1);
                 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 = textlib::strtolower($username);
         // Compatibility hack
         set_cache_flag($this->pluginconfig . '/ntlmsess', $sesskey, $username, AUTH_NTLMTIMEOUT);
         return true;
     }
     return false;
 }
开发者ID:nigeli,项目名称:moodle,代码行数:46,代码来源:auth.php

示例15: toolbook_importhtml_fix_encoding

/**
 * Convert some html content to utf8, getting original encoding from html headers
 *
 * @param string $html html content to convert
 * @return string html content converted to utf8
 */
function toolbook_importhtml_fix_encoding($html) {
    if (preg_match('/<head[^>]*>(.+)<\/head>/is', $html, $matches)) {
        $head = $matches[1];
        if (preg_match('/charset=([^"]+)/is', $head, $matches)) {
            $enc = $matches[1];
            return textlib::convert($html, $enc, 'utf-8');
        }
    }
    return iconv('UTF-8', 'UTF-8//IGNORE', $html);
}
开发者ID:Jtgadbois,项目名称:Pedadida,代码行数:16,代码来源:locallib.php


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