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


PHP StringHelper::convertToUTF8方法代码示例

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


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

示例1: actionDownload

 /**
  * Download a CSV of the changes list.
  */
 public function actionDownload()
 {
     // Get criteria
     $criteria = craft()->elements->getCriteria('AuditLog', craft()->request->getParam('criteria'));
     // Get element type
     $elementType = craft()->elements->getElementType('AuditLog');
     // Get order and sort
     $viewState = craft()->request->getParam('viewState', array('order' => 'id', 'sort' => 'desc'));
     // Set sort on criteria
     $criteria->order = $viewState['order'] == 'score' ? 'id' : $viewState['order'] . ' ' . $viewState['sort'];
     // Did we search?
     $criteria->search = craft()->request->getParam('search');
     // Get source
     $sources = $elementType->getSources();
     $source = craft()->request->getParam('source', '*');
     // Set type
     $criteria->type = $source != '*' ? $sources[$source]['criteria']['type'] : null;
     // Get data
     $log = craft()->auditLog->log($criteria);
     // Set status attribute
     $attributes = array('status' => Craft::t('Status'));
     // Get nice attributes
     $availableAttributes = $elementType->defineAvailableTableAttributes();
     // Make 'em fit
     foreach ($availableAttributes as $key => $result) {
         $attributes[$key] = $result['label'];
     }
     // Ditch the changes button
     unset($attributes['changes']);
     // Re-order data
     $data = StringHelper::convertToUTF8('"' . implode('","', $attributes) . "\"\r\n");
     foreach ($log as $element) {
         // Gather parsed fields
         $fields = array();
         // Parse fields
         foreach ($attributes as $handle => $field) {
             $fields[] = $handle == 'status' ? $elementType->getStatuses()[$element->{$handle}] : strip_tags($elementType->getTableAttributeHtml($element, $handle));
         }
         // Set data
         $data .= StringHelper::convertToUTF8('"' . implode('","', $fields) . "\"\r\n");
     }
     // Download the file
     craft()->request->sendFile('auditlog.csv', $data, array('forceDownload' => true, 'mimeType' => 'text/csv'));
 }
开发者ID:boboldehampsink,项目名称:auditlog,代码行数:47,代码来源:AuditLogController.php

示例2: actionDownload

 /**
  * Download translations.
  */
 public function actionDownload()
 {
     // Get params
     $locale = craft()->request->getParam('locale');
     // Set criteria
     $criteria = craft()->elements->getCriteria('Translate');
     $criteria->search = false;
     $criteria->status = false;
     $criteria->locale = $locale;
     $criteria->source = array(craft()->path->getPluginsPath(), craft()->path->getSiteTemplatesPath());
     // Get occurences
     $occurences = craft()->translate->get($criteria);
     // Re-order data
     $data = StringHelper::convertToUTF8('"' . Craft::t('Original') . '","' . Craft::t('Translation') . "\"\r\n");
     foreach ($occurences as $element) {
         $data .= StringHelper::convertToUTF8('"' . $element->original . '","' . $element->translation . "\"\r\n");
     }
     // Download the file
     craft()->request->sendFile('translations_' . $locale . '.csv', $data, array('forceDownload' => true, 'mimeType' => 'text/csv'));
 }
开发者ID:webremote,项目名称:translate,代码行数:23,代码来源:TranslateController.php

示例3: prepForFieldType

 /**
  * Prepare fields for fieldtypes.
  *
  * @param string &$data
  * @param string $handle
  *
  * @return mixed
  */
 public function prepForFieldType(&$data, $handle)
 {
     // Fresh up $data
     $data = StringHelper::convertToUTF8($data);
     $data = trim($data);
     // Get field info
     $field = craft()->fields->getFieldByHandle($handle);
     // If it's a field ofcourse
     if (!is_null($field)) {
         // For some fieldtypes the're special rules
         switch ($field->type) {
             case ImportModel::FieldTypeEntries:
                 // No newlines allowed
                 $data = str_replace("\n", '', $data);
                 $data = str_replace("\r", '', $data);
                 // Don't connect empty fields
                 if (!empty($data)) {
                     // Get field settings
                     $settings = $field->getFieldType()->getSettings();
                     // Get source id's for connecting
                     $sectionIds = array();
                     $sources = $settings->sources;
                     if (is_array($sources)) {
                         foreach ($sources as $source) {
                             list($type, $id) = explode(':', $source);
                             $sectionIds[] = $id;
                         }
                     }
                     // Find matching element in sections
                     $criteria = craft()->elements->getCriteria(ElementType::Entry);
                     $criteria->sectionId = $sectionIds;
                     $criteria->limit = $settings->limit;
                     // Get search strings
                     $search = ArrayHelper::stringToArray($data);
                     // Ability to import multiple Assets at once
                     $data = array();
                     // Loop through keywords
                     foreach ($search as $query) {
                         // Search
                         $criteria->search = $query;
                         // Add to data
                         $data = array_merge($data, $criteria->ids());
                     }
                 } else {
                     // Return empty array
                     $data = array();
                 }
                 break;
             case ImportModel::FieldTypeCategories:
                 // Don't connect empty fields
                 if (!empty($data)) {
                     // Get field settings
                     $settings = $field->getFieldType()->getSettings();
                     // Get source id
                     $source = $settings->source;
                     list($type, $id) = explode(':', $source);
                     // Get category data
                     $category = new CategoryModel();
                     $category->groupId = $id;
                     // This we append before the slugified path
                     $categoryUrl = str_replace('{slug}', '', $category->getUrlFormat());
                     // Find matching elements in categories
                     $criteria = craft()->elements->getCriteria(ElementType::Category);
                     $criteria->groupId = $id;
                     $criteria->limit = $settings->limit;
                     // Get search strings
                     $search = ArrayHelper::stringToArray($data);
                     // Ability to import multiple Categories at once
                     $data = array();
                     // Loop through keywords
                     foreach ($search as $query) {
                         // Find matching element by URI (dirty, not all categories have URI's)
                         $criteria->uri = $categoryUrl . $this->slugify($query);
                         // Add to data
                         $data = array_merge($data, $criteria->ids());
                     }
                 } else {
                     // Return empty array
                     $data = array();
                 }
                 break;
             case ImportModel::FieldTypeAssets:
                 // Don't connect empty fields
                 if (!empty($data)) {
                     // Get field settings
                     $settings = $field->getFieldType()->getSettings();
                     // Get folder id's for connecting
                     $folderIds = array();
                     $folders = $settings->sources;
                     if (is_array($folders)) {
                         foreach ($folders as $folder) {
                             list($type, $id) = explode(':', $folder);
//.........这里部分代码省略.........
开发者ID:ianshea,项目名称:import,代码行数:101,代码来源:ImportService.php

示例4: _utf8AllTheThings

 /**
  * @param array|string $things
  *
  * @return mixed
  */
 private function _utf8AllTheThings($things)
 {
     if (is_array($things)) {
         foreach ($things as $key => $value) {
             if (is_array($value)) {
                 $things[$key] = $this->_utf8AllTheThings($value);
             } else {
                 $things[$key] = StringHelper::convertToUTF8($value);
             }
         }
     } else {
         $things = StringHelper::convertToUTF8($things);
     }
     return $things;
 }
开发者ID:nathanedwards,项目名称:cowfields.craft,代码行数:20,代码来源:HttpRequestService.php

示例5: prepForFieldType

 public function prepForFieldType(&$data, $handle, $field = null)
 {
     if (!is_array($data)) {
         $data = StringHelper::convertToUTF8($data);
         $data = trim($data);
     }
     if (!$field) {
         // Check for sub-fields, we only want to grab the top-level handle (for now)
         preg_match('/(\\w+)/', $handle, $matches);
         $fieldHandle = $matches[0];
         if (isset($this->_entryFields[$fieldHandle])) {
             $field = $this->_entryFields[$fieldHandle];
         } else {
             $field = craft()->fields->getFieldByHandle($fieldHandle);
             $this->_entryFields[$fieldHandle] = $field;
         }
     } else {
         $fieldHandle = $handle;
     }
     if (!is_null($field)) {
         switch ($field->type) {
             case FeedMe_FieldType::Assets:
                 $data = array($fieldHandle => $this->prepAssets($data, $field));
                 break;
             case FeedMe_FieldType::Categories:
                 $data = array($fieldHandle => $this->prepCategories($data, $field));
                 break;
             case FeedMe_FieldType::Checkboxes:
                 $data = array($fieldHandle => $this->prepCheckboxes($data, $field));
                 break;
             case FeedMe_FieldType::Date:
                 $data = array($fieldHandle => $this->prepDate($data, $field));
                 break;
             case FeedMe_FieldType::Dropdown:
                 $data = array($fieldHandle => $this->prepDropdown($data, $field));
                 break;
             case FeedMe_FieldType::Entries:
                 $data = array($fieldHandle => $this->prepEntries($data, $field));
                 break;
             case FeedMe_FieldType::Matrix:
                 $data = array($fieldHandle => $this->prepMatrix($data, $handle, $field));
                 break;
             case FeedMe_FieldType::MultiSelect:
                 $data = array($fieldHandle => $this->prepMultiSelect($data, $field));
                 break;
             case FeedMe_FieldType::Number:
                 $data = array($fieldHandle => $this->prepNumber($data, $field));
                 break;
             case FeedMe_FieldType::RadioButtons:
                 $data = array($fieldHandle => $this->prepRadioButtons($data, $field));
                 break;
             case FeedMe_FieldType::RichText:
                 $data = array($fieldHandle => $this->prepRichText($data, $field));
                 break;
             case FeedMe_FieldType::Table:
                 $data = array($fieldHandle => $this->prepTable($data, $handle, $field));
                 break;
             case FeedMe_FieldType::Tags:
                 $data = array($fieldHandle => $this->prepTags($data, $field));
                 break;
             case FeedMe_FieldType::Users:
                 $data = array($fieldHandle => $this->prepUsers($data, $field));
                 break;
                 // Color, Lightswitch, PlainText, PositionSelect all take care of themselves
             // Color, Lightswitch, PlainText, PositionSelect all take care of themselves
             default:
                 $data = array($fieldHandle => $data);
         }
         // Third-party fieldtype support
         craft()->plugins->call('prepForFeedMeFieldType', array($field, &$data, $handle));
     } else {
         // For core entry fields - still need to return with handle
         $data = array($fieldHandle => $data);
     }
     return $data;
 }
开发者ID:Tcheu,项目名称:FeedMe,代码行数:76,代码来源:FeedMe_FieldsService.php

示例6: parseColumns

 /**
  * Parse column names.
  *
  * @param array $settings [description]
  *
  * @return string
  */
 protected function parseColumns(array $settings)
 {
     $columns = array();
     // Loop trough map
     foreach ($settings['map'] as $handle => $data) {
         // If checked
         if ($data['checked'] == 1) {
             // Add column
             $columns[] = StringHelper::convertToUTF8($data['label']);
         }
     }
     return $columns;
 }
开发者ID:rutgerbakker7,项目名称:export,代码行数:20,代码来源:ExportService.php

示例7: prepForFieldType

 public function prepForFieldType(&$data, &$handle, $field = null)
 {
     if (!is_array($data)) {
         $data = StringHelper::convertToUTF8($data);
         $data = trim($data);
     }
     if (!$field) {
         $field = craft()->fields->getFieldByHandle($handle);
     }
     // Special case for Matrix fields
     if (substr($handle, 0, 10) == '__matrix__') {
         $handle = str_replace('__matrix__', '', $handle);
         // [0]matrix - [1]blocktype - [2]field
         $matrixInfo = explode('__', $handle);
         $field = craft()->fields->getFieldByHandle($matrixInfo[0]);
     }
     // Special case for SuperTable fields
     if (substr($handle, 0, 14) == '__supertable__') {
         $handle = str_replace('__supertable__', '', $handle);
         // [0]matrix - [1]blocktype - [2]field
         $matrixInfo = explode('__', $handle);
         $field = craft()->fields->getFieldByHandle($matrixInfo[0]);
     }
     // Special case for Table fields
     if (substr($handle, 0, 9) == '__table__') {
         $handle = str_replace('__table__', '', $handle);
         // [0]table - [1]column
         $tableInfo = explode('__', $handle);
         $field = craft()->fields->getFieldByHandle($tableInfo[0]);
     }
     if (!is_null($field)) {
         switch ($field->type) {
             case FeedMe_FieldType::Assets:
                 $data = $this->prepAssets($data, $field);
                 break;
             case FeedMe_FieldType::Categories:
                 $data = $this->prepCategories($data, $field);
                 break;
             case FeedMe_FieldType::Checkboxes:
                 $data = $this->prepCheckboxes($data, $field);
                 break;
             case FeedMe_FieldType::Date:
                 $data = $this->prepDate($data, $field);
                 break;
             case FeedMe_FieldType::Dropdown:
                 $data = $this->prepDropdown($data, $field);
                 break;
             case FeedMe_FieldType::Entries:
                 $data = $this->prepEntries($data, $field);
                 break;
             case FeedMe_FieldType::Matrix:
                 $data = $this->prepMatrix($data, $matrixInfo, $field, $handle);
                 break;
             case FeedMe_FieldType::MultiSelect:
                 $data = $this->prepMultiSelect($data, $field);
                 break;
             case FeedMe_FieldType::Number:
                 $data = $this->prepNumber($data, $field);
                 break;
             case FeedMe_FieldType::RadioButtons:
                 $data = $this->prepRadioButtons($data, $field);
                 break;
             case FeedMe_FieldType::RichText:
                 $data = $this->prepRichText($data, $field);
                 break;
             case FeedMe_FieldType::Table:
                 $data = $this->prepTable($data, $tableInfo, $field, $handle);
                 break;
             case FeedMe_FieldType::Tags:
                 $data = $this->prepTags($data, $field);
                 break;
             case FeedMe_FieldType::Users:
                 $data = $this->prepUsers($data, $field);
                 break;
                 // Color, Lightswitch, PlainText, PositionSelect all take care of themselves
                 // Third-Party
             // Color, Lightswitch, PlainText, PositionSelect all take care of themselves
             // Third-Party
             case FeedMe_FieldType::SuperTable:
                 $data = $this->prepSuperTable($data, $matrixInfo, $field, $handle);
                 break;
         }
         // Third-party fieldtype support
         $thirdPartyFields = craft()->plugins->call('registerFeedMeField');
         if (in_array($field->type, $thirdPartyFields)) {
             craft()->plugins->call('prepForFeedMeFieldType', array(&$data, $handle));
         }
     }
     return $data;
 }
开发者ID:am-impact,项目名称:FeedMe,代码行数:90,代码来源:FeedMe_FieldsService.php

示例8: prepForFieldType

 /**
  * Prepare fields for fieldtypes.
  *
  * @param string &$data
  * @param string $handle
  *
  * @return mixed
  */
 public function prepForFieldType(&$data, $handle)
 {
     // Fresh up $data
     $data = StringHelper::convertToUTF8($data);
     $data = trim($data);
     // Get field info
     $field = craft()->fields->getFieldByHandle($handle);
     // If it's a field ofcourse
     if (!is_null($field)) {
         // For some fieldtypes the're special rules
         switch ($field->type) {
             case ImportModel::FieldTypeEntries:
                 // No newlines allowed
                 $data = str_replace("\n", '', $data);
                 $data = str_replace("\r", '', $data);
                 // Don't connect empty fields
                 if (!empty($data)) {
                     $data = $this->prepEntriesFieldType($data, $field);
                 } else {
                     $data = array();
                 }
                 break;
             case ImportModel::FieldTypeCategories:
                 if (!empty($data)) {
                     $data = $this->prepCategoriesFieldType($data, $field);
                 } else {
                     $data = array();
                 }
                 break;
             case ImportModel::FieldTypeAssets:
                 if (!empty($data)) {
                     $data = $this->prepAssetsFieldType($data, $field);
                 } else {
                     $data = array();
                 }
                 break;
             case ImportModel::FieldTypeUsers:
                 if (!empty($data)) {
                     $data = $this->prepUsersFieldType($data, $field);
                 } else {
                     $data = array();
                 }
                 break;
             case ImportModel::FieldTypeTags:
                 $data = $this->prepTagsFieldType($data, $field);
                 break;
             case ImportModel::FieldTypeNumber:
                 // Parse as numberx
                 $data = LocalizationHelper::normalizeNumber($data);
                 // Parse as float
                 $data = floatval($data);
                 break;
             case ImportModel::FieldTypeDate:
                 // Parse date from string
                 $data = DateTimeHelper::formatTimeForDb(DateTimeHelper::fromString($data, craft()->timezone));
                 break;
             case ImportModel::FieldTypeRadioButtons:
             case ImportModel::FieldTypeDropdown:
                 //get field settings
                 $data = $this->prepDropDownFieldType($data, $field);
                 break;
             case ImportModel::FieldTypeCheckboxes:
             case ImportModel::FieldTypeMultiSelect:
                 // Convert to array
                 $data = ArrayHelper::stringToArray($data);
                 break;
             case ImportModel::FieldTypeLightSwitch:
                 // Convert yes/no values to boolean
                 switch ($data) {
                     case Craft::t('Yes'):
                         $data = true;
                         break;
                     case Craft::t('No'):
                         $data = false;
                         break;
                 }
                 break;
         }
     }
     return $data;
 }
开发者ID:transomdesign,项目名称:transom-craft-starter,代码行数:89,代码来源:ImportService.php

示例9: _getElementExcerpt

 /**
  * Get an element's excerpt.
  *
  * @param array $element
  *
  * @return string
  */
 private function _getElementExcerpt($element)
 {
     // What is our excerpt key?
     $excerptKey = $this->_getCollectionSetting('excerptKey');
     // Do we have an excerpt option?
     if (empty($excerptKey) || !isset($element[$excerptKey])) {
         return '';
     }
     // Get our full string
     $fullString = $element[$excerptKey];
     // Strip HTML from string
     $fullString = StringHelper::stripHtml($fullString);
     // Do we even have keywords?
     if (!$this->_keywords) {
         return $fullString;
     }
     // Excerpt settings
     $prefix = $this->_excerptPrefix;
     $suffix = $this->_excerptSuffix;
     // Where are the keywords located?
     $keywordsPosition = stripos($fullString, $this->_keywords);
     // Find start
     $extractStart = $keywordsPosition - $this->_charsBeforeKeywords;
     if ($extractStart < 0) {
         $extractStart = 0;
         $prefix = '';
     }
     // Find end
     $extractEnd = $keywordsPosition + strlen($this->_keywords) + $this->_charsAfterKeywords;
     if ($extractEnd > strlen($fullString)) {
         $extractEnd = strlen($fullString);
         $suffix = '';
     }
     // Get excerpt!
     $plainText = substr($fullString, $extractStart, $extractEnd - $extractStart);
     $plainText = preg_replace("/(" . $this->_keywords . ")/i", "<strong>\$1</strong>", StringHelper::convertToUTF8($plainText));
     // Handle CP request differently, otherwise while testing, the excerpt has become an object
     if (craft()->request->isCpRequest()) {
         return $prefix . $plainText . $suffix;
     }
     return new \Twig_Markup($prefix . $plainText . $suffix, craft()->templates->getTwig()->getCharset());
 }
开发者ID:am-impact,项目名称:amsearch,代码行数:49,代码来源:AmSearch_SearchService.php


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