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


PHP Localization::translateCharset方法代码示例

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


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

示例1: translateCharacters

 /**
  * Performs character set and HTML character translations on the string.
  *
  * @access public
  * @param string       $string      required The string that is to be translated.
  * @param Localization $locale      required The locale object for doing the character set translation.
  * @param string       $toCharset   required Translate to this character set.
  * @param string       $fromCharset          Translate from this character set.
  * @return string The translated string.
  */
 public function translateCharacters($string, Localization $locale, $toCharset, $fromCharset = "UTF-8")
 {
     // perform character set translations on the string
     $string = $locale->translateCharset($string, $fromCharset, $toCharset);
     // perform HTML character translations on the string
     $string = from_html($string);
     return $string;
 }
开发者ID:jglaine,项目名称:sugar761-ent,代码行数:18,代码来源:EmailFormatter.php

示例2: importVCard

 function importVCard($filename, $module = 'Contacts')
 {
     global $current_user;
     $lines = file($filename);
     $start = false;
     $contact = loadBean($module);
     $contact->title = 'imported';
     $contact->assigned_user_id = $current_user->id;
     $fullname = '';
     $email_suffix = 1;
     for ($index = 0; $index < sizeof($lines); $index++) {
         $line = $lines[$index];
         // check the encoding and change it if needed
         $locale = new Localization();
         $encoding = $locale->detectCharset($line);
         if ($encoding != $GLOBALS['sugar_config']['default_charset']) {
             $line = $locale->translateCharset($line, $encoding);
         }
         $line = trim($line);
         if ($start) {
             //VCARD is done
             if (substr_count(strtoupper($line), 'END:VCARD')) {
                 if (!isset($contact->last_name)) {
                     $contact->last_name = $fullname;
                 }
                 break;
             }
             $keyvalue = explode(':', $line);
             if (sizeof($keyvalue) == 2) {
                 $value = $keyvalue[1];
                 for ($newindex = $index + 1; $newindex < sizeof($lines), substr_count($lines[$newindex], ':') == 0; $newindex++) {
                     $value .= $lines[$newindex];
                     $index = $newindex;
                 }
                 $values = explode(';', $value);
                 $key = strtoupper($keyvalue[0]);
                 $key = strtr($key, '=', '');
                 $key = strtr($key, ',', ';');
                 $keys = explode(';', $key);
                 if ($keys[0] == 'TEL') {
                     if (substr_count($key, 'WORK') > 0) {
                         if (substr_count($key, 'FAX') > 0) {
                             if (!isset($contact->phone_fax)) {
                                 $contact->phone_fax = $value;
                             }
                         } else {
                             if (!isset($contact->phone_work)) {
                                 $contact->phone_work = $value;
                             }
                         }
                     }
                     if (substr_count($key, 'HOME') > 0) {
                         if (substr_count($key, 'FAX') > 0) {
                             if (!isset($contact->phone_fax)) {
                                 $contact->phone_fax = $value;
                             }
                         } else {
                             if (!isset($contact->phone_home)) {
                                 $contact->phone_home = $value;
                             }
                         }
                     }
                     if (substr_count($key, 'CELL') > 0) {
                         if (!isset($contact->phone_mobile)) {
                             $contact->phone_mobile = $value;
                         }
                     }
                     if (substr_count($key, 'FAX') > 0) {
                         if (!isset($contact->phone_fax)) {
                             $contact->phone_fax = $value;
                         }
                     }
                 }
                 if ($keys[0] == 'N') {
                     if (sizeof($values) > 0) {
                         $contact->last_name = $values[0];
                     }
                     if (sizeof($values) > 1) {
                         $contact->first_name = $values[1];
                     }
                     if (sizeof($values) > 2) {
                         $contact->salutation = $values[2];
                     }
                 }
                 if ($keys[0] == 'FN') {
                     $fullname = $value;
                 }
             }
             if ($keys[0] == 'ADR') {
                 if (substr_count($key, 'WORK') > 0 && (substr_count($key, 'POSTAL') > 0 || substr_count($key, 'PARCEL') == 0)) {
                     if (!isset($contact->primary_address_street) && sizeof($values) > 2) {
                         $textBreaks = array("\n", "\r");
                         $vcardBreaks = array("=0A", "=0D");
                         $contact->primary_address_street = str_replace($vcardBreaks, $textBreaks, $values[2]);
                     }
                     if (!isset($contact->primary_address_city) && sizeof($values) > 3) {
                         $contact->primary_address_city = $values[3];
                     }
                     if (!isset($contact->primary_address_state) && sizeof($values) > 4) {
                         $contact->primary_address_state = $values[4];
//.........这里部分代码省略.........
开发者ID:aldridged,项目名称:gtg-sugar,代码行数:101,代码来源:vCard.php

示例3: importRow

 protected function importRow($row)
 {
     global $sugar_config, $mod_strings, $current_user;
     $focus = clone $this->bean;
     $focus->unPopulateDefaultValues();
     $focus->save_from_post = false;
     $focus->team_id = null;
     $this->ifs->createdBeans = array();
     $this->importSource->resetRowErrorCounter();
     $do_save = true;
     for ($fieldNum = 0; $fieldNum < $_REQUEST['columncount']; $fieldNum++) {
         // loop if this column isn't set
         if (!isset($this->importColumns[$fieldNum])) {
             continue;
         }
         // get this field's properties
         $field = $this->importColumns[$fieldNum];
         $fieldDef = $focus->getFieldDefinition($field);
         $fieldTranslated = translate(isset($fieldDef['vname']) ? $fieldDef['vname'] : $fieldDef['name'], $focus->module_dir) . " (" . $fieldDef['name'] . ")";
         $defaultRowValue = '';
         // Bug 37241 - Don't re-import over a field we already set during the importing of another field
         if (!empty($focus->{$field})) {
             continue;
         }
         // translate strings
         global $locale;
         if (empty($locale)) {
             $locale = new Localization();
         }
         if (isset($row[$fieldNum])) {
             $rowValue = $locale->translateCharset(strip_tags(trim($row[$fieldNum])), $this->importSource->importlocale_charset, $sugar_config['default_charset']);
         } else {
             if (isset($this->sugarToExternalSourceFieldMap[$field]) && isset($row[$this->sugarToExternalSourceFieldMap[$field]])) {
                 $rowValue = $locale->translateCharset(strip_tags(trim($row[$this->sugarToExternalSourceFieldMap[$field]])), $this->importSource->importlocale_charset, $sugar_config['default_charset']);
             } else {
                 $rowValue = '';
             }
         }
         // If there is an default value then use it instead
         if (!empty($_REQUEST[$field])) {
             $defaultRowValue = $this->populateDefaultMapValue($field, $_REQUEST[$field], $fieldDef);
             if (empty($rowValue)) {
                 $rowValue = $defaultRowValue;
                 //reset the default value to empty
                 $defaultRowValue = '';
             }
         }
         // Bug 22705 - Don't update the First Name or Last Name value if Full Name is set
         if (in_array($field, array('first_name', 'last_name')) && !empty($focus->full_name)) {
             continue;
         }
         // loop if this value has not been set
         if (!isset($rowValue)) {
             continue;
         }
         // If the field is required and blank then error out
         if (array_key_exists($field, $focus->get_import_required_fields()) && empty($rowValue) && $rowValue != '0') {
             $this->importSource->writeError($mod_strings['LBL_REQUIRED_VALUE'], $fieldTranslated, 'NULL');
             $do_save = false;
         }
         // Handle the special case "Sync to Outlook"
         if ($focus->object_name == "Contact" && $field == 'sync_contact') {
             /**
              * Bug #41194 : if true used as value of sync_contact - add curent user to list to sync
              */
             if (true == $rowValue || 'true' == strtolower($rowValue)) {
                 $focus->sync_contact = $focus->id;
             } elseif (false == $rowValue || 'false' == strtolower($rowValue)) {
                 $focus->sync_contact = '';
             } else {
                 $bad_names = array();
                 $returnValue = $this->ifs->synctooutlook($rowValue, $fieldDef, $bad_names);
                 // try the default value on fail
                 if (!$returnValue && !empty($defaultRowValue)) {
                     $returnValue = $this->ifs->synctooutlook($defaultRowValue, $fieldDef, $bad_names);
                 }
                 if (!$returnValue) {
                     $this->importSource->writeError($mod_strings['LBL_ERROR_SYNC_USERS'], $fieldTranslated, $bad_names);
                     $do_save = 0;
                 } else {
                     $focus->sync_contact = $returnValue;
                 }
             }
         }
         // Handle email field, if it's a semi-colon separated export
         if ($field == 'email_addresses_non_primary' && !empty($rowValue)) {
             if (strpos($rowValue, ';') !== false) {
                 $rowValue = explode(';', $rowValue);
             } else {
                 $rowValue = array($rowValue);
             }
         }
         // Handle email1 and email2 fields ( these don't have the type of email )
         if ($field == 'email1' || $field == 'email2') {
             $returnValue = $this->ifs->email($rowValue, $fieldDef, $focus);
             // try the default value on fail
             if (!$returnValue && !empty($defaultRowValue)) {
                 $returnValue = $this->ifs->email($defaultRowValue, $fieldDef);
             }
             if ($returnValue === FALSE) {
//.........这里部分代码省略.........
开发者ID:delkyd,项目名称:sugarcrm_dev,代码行数:101,代码来源:Importer.php

示例4: display

 /** 
  * @see SugarView::display()
  */
 public function display()
 {
     global $sugar_config;
     // Increase the max_execution_time since this step can take awhile
     ini_set("max_execution_time", max($sugar_config['import_max_execution_time'], 3600));
     // stop the tracker
     TrackerManager::getInstance()->pause();
     // use our own error handler
     set_error_handler('handleImportErrors', E_ALL);
     global $mod_strings, $app_strings, $current_user, $import_bean_map;
     global $app_list_strings, $timedate;
     $update_only = isset($_REQUEST['import_type']) && $_REQUEST['import_type'] == 'update';
     $firstrow = unserialize(base64_decode($_REQUEST['firstrow']));
     // All the Look Up Caches are initialized here
     $enum_lookup_cache = array();
     // Let's try and load the import bean
     $focus = loadImportBean($_REQUEST['import_module']);
     if (!$focus) {
         trigger_error($mod_strings['LBL_ERROR_IMPORTS_NOT_SET_UP'], E_USER_ERROR);
     }
     // setup the importable fields array.
     $importable_fields = $focus->get_importable_fields();
     // loop through all request variables
     $importColumns = array();
     foreach ($_REQUEST as $name => $value) {
         // only look for var names that start with "fieldNum"
         if (strncasecmp($name, "colnum_", 7) != 0) {
             continue;
         }
         // pull out the column position for this field name
         $pos = substr($name, 7);
         if (isset($importable_fields[$value])) {
             // now mark that we've seen this field
             $importColumns[$pos] = $value;
         }
     }
     // set the default locale settings
     $ifs = new ImportFieldSanitize();
     $ifs->dateformat = $_REQUEST['importlocale_dateformat'];
     $ifs->timeformat = $_REQUEST['importlocale_timeformat'];
     $ifs->timezone = $_REQUEST['importlocale_timezone'];
     $currency = new Currency();
     $currency->retrieve($_REQUEST['importlocale_currency']);
     $ifs->currency_symbol = $currency->symbol;
     $ifs->default_currency_significant_digits = $_REQUEST['importlocale_default_currency_significant_digits'];
     $ifs->num_grp_sep = $_REQUEST['importlocale_num_grp_sep'];
     $ifs->dec_sep = $_REQUEST['importlocale_dec_sep'];
     $ifs->default_locale_name_format = $_REQUEST['importlocale_default_locale_name_format'];
     // Check to be sure we are getting an import file that is in the right place
     if (realpath(dirname($_REQUEST['tmp_file']) . '/') != realpath($sugar_config['upload_dir'])) {
         trigger_error($mod_strings['LBL_CANNOT_OPEN'], E_USER_ERROR);
     }
     // Open the import file
     $importFile = new ImportFile($_REQUEST['tmp_file'], $_REQUEST['custom_delimiter'], html_entity_decode($_REQUEST['custom_enclosure'], ENT_QUOTES));
     if (!$importFile->fileExists()) {
         trigger_error($mod_strings['LBL_CANNOT_OPEN'], E_USER_ERROR);
     }
     $fieldDefs = $focus->getFieldDefinitions();
     unset($focus);
     while ($row = $importFile->getNextRow()) {
         $focus = loadImportBean($_REQUEST['import_module']);
         $focus->unPopulateDefaultValues();
         $focus->save_from_post = false;
         $focus->team_id = null;
         $ifs->createdBeans = array();
         $do_save = true;
         for ($fieldNum = 0; $fieldNum < $_REQUEST['columncount']; $fieldNum++) {
             // loop if this column isn't set
             if (!isset($importColumns[$fieldNum])) {
                 continue;
             }
             // get this field's properties
             $field = $importColumns[$fieldNum];
             $fieldDef = $focus->getFieldDefinition($field);
             $fieldTranslated = translate(isset($fieldDef['vname']) ? $fieldDef['vname'] : $fieldDef['name'], $_REQUEST['module']) . " (" . $fieldDef['name'] . ")";
             // Bug 37241 - Don't re-import over a field we already set during the importing of another field
             if (!empty($focus->{$field})) {
                 continue;
             }
             //DETERMINE WHETHER OR NOT $fieldDef['name'] IS DATE_MODIFIED AND SET A VAR, USE DOWN BELOW
             // translate strings
             global $locale;
             if (empty($locale)) {
                 $locale = new Localization();
             }
             if (isset($row[$fieldNum])) {
                 $rowValue = $locale->translateCharset(strip_tags(trim($row[$fieldNum])), $_REQUEST['importlocale_charset'], $sugar_config['default_charset']);
             } else {
                 $rowValue = '';
             }
             // If there is an default value then use it instead
             if (!empty($_REQUEST[$field])) {
                 if (is_array($_REQUEST[$field])) {
                     $defaultRowValue = encodeMultienumValue($_REQUEST[$field]);
                 } else {
                     $defaultRowValue = $_REQUEST[$field];
                 }
//.........这里部分代码省略.........
开发者ID:aldridged,项目名称:gtg-sugar,代码行数:101,代码来源:view.step4.php

示例5: parse_import_act

function parse_import_act($file_name, $delimiter, $max_lines, $has_header)
{
    global $locale;
    if (empty($locale)) {
        require_once 'include/Localization/Localization.php';
        $locale = new Localization();
    }
    $line_count = 0;
    $field_count = 0;
    $rows = array();
    if (!file_exists($file_name)) {
        return -1;
    }
    $fh = fopen($file_name, "r");
    if (!$fh) {
        return -1;
    }
    while (($line = fgets($fh, 4096)) && ($max_lines == -1 || $line_count < $max_lines)) {
        $line = trim($line);
        $line = substr_replace($line, "", 0, 1);
        $line = substr_replace($line, "", -1);
        $fields = explode("\",\"", $line);
        $this_field_count = count($fields);
        if ($this_field_count > $field_count) {
            $field_count = $this_field_count;
        }
        array_push($rows, $fields);
        $line_count++;
    }
    // got no rows
    if (count($rows) == 0) {
        return -3;
    } else {
        //// cn: bug 6712 - need to translate to UTF-8
        foreach ($rows as $rowKey => $row) {
            foreach ($row as $k => $v) {
                $row[$k] = $locale->translateCharset($v, $locale->getExportCharset());
            }
            $rows[$rowKey] = $row;
        }
    }
    $ret_array = array("rows" => &$rows, "field_count" => $field_count);
    return $ret_array;
}
开发者ID:BackupTheBerlios,项目名称:livealphaprint,代码行数:44,代码来源:parse_utils.php


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