本文整理汇总了PHP中TYPO3\CMS\Core\Utility\StringUtility类的典型用法代码示例。如果您正苦于以下问题:PHP StringUtility类的具体用法?PHP StringUtility怎么用?PHP StringUtility使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了StringUtility类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: renderHtml
public function renderHtml($name, $value, $options)
{
$width = $options['width'];
// TODO: das Feld beachten!
$maxlength = $options['maxlength'];
$attributes = array();
// for data-formengine-input-params
$paramsList = array('field' => $name, 'evalList' => 'int', 'is_in' => '');
$attributes['id'] = StringUtility::getUniqueId('formengine-input-');
$attributes['value'] = '';
$attributes['data-formengine-validation-rules'] = json_encode(array('type' => 'int'));
$attributes['data-formengine-input-params'] = json_encode($paramsList);
$attributes['data-formengine-input-name'] = htmlspecialchars($name);
$attributeString = '';
foreach ($attributes as $attributeName => $attributeValue) {
$attributeString .= ' ' . $attributeName . '="' . htmlspecialchars($attributeValue) . '"';
}
//$width = (int)$this->formMaxWidth($size);
$width = $GLOBALS['TBE_TEMPLATE']->formWidth($width);
$html = '
<input type="text"' . $attributeString . $width . ' />';
// This is the ACTUAL form field - values from the EDITABLE field must be transferred to this field which is the one that is written to the database.
$html .= '<input type="hidden" name="' . $name . '" value="' . htmlspecialchars($value) . '" />';
// Den Wrap lassen wir weg, weil es zu einem Zeilenumbruch kommt
// $html = '<div class="form-control-wrap"' . $width . '>' . $html . '</div>';
return $html;
}
示例2: fetchType
/**
* Type fetching method, based on the type that softRefParserObj returns
*
* @param array $value Reference properties
* @param string $type Current type
* @param string $key Validator hook name
* @return string fetched type
*/
public function fetchType($value, $type, $key)
{
if (StringUtility::beginswith(strtolower($value['tokenValue']), 'file:')) {
$type = 'file';
}
return $type;
}
示例3: render
/**
* Handler for unknown types.
*
* @return array As defined in initializeResultArray() of AbstractNode
*/
public function render()
{
$resultArray = $this->initializeResultArray();
$languageService = $this->getLanguageService();
$row = $this->data['databaseRow'];
$parameterArray = $this->data['parameterArray'];
// If ratios are set do not add default options
if (isset($parameterArray['fieldConf']['config']['ratios'])) {
unset($this->defaultConfig['ratios']);
}
$config = ArrayUtility::arrayMergeRecursiveOverrule($this->defaultConfig, $parameterArray['fieldConf']['config']);
// By default we allow all image extensions that can be handled by the GFX functionality
if ($config['allowedExtensions'] === null) {
$config['allowedExtensions'] = $GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'];
}
if ($config['readOnly']) {
$options = array();
$options['parameterArray'] = array('fieldConf' => array('config' => $config), 'itemFormElValue' => $parameterArray['itemFormElValue']);
$options['renderType'] = 'none';
return $this->nodeFactory->create($options)->render();
}
$file = $this->getFile($row, $config['file_field']);
if (!$file) {
return $resultArray;
}
$content = '';
$preview = '';
if (GeneralUtility::inList(mb_strtolower($config['allowedExtensions']), mb_strtolower($file->getExtension()))) {
// Get preview
$preview = $this->getPreview($file, $parameterArray['itemFormElValue']);
// Check if ratio labels hold translation strings
foreach ((array) $config['ratios'] as $ratio => $label) {
$config['ratios'][$ratio] = $languageService->sL($label, true);
}
$formFieldId = StringUtility::getUniqueId('formengine-image-manipulation-');
$wizardData = array('zoom' => $config['enableZoom'] ? '1' : '0', 'ratios' => json_encode($config['ratios']), 'file' => $file->getUid());
$wizardData['token'] = GeneralUtility::hmac(implode('|', $wizardData), 'ImageManipulationWizard');
$buttonAttributes = array('data-url' => BackendUtility::getAjaxUrl('wizard_image_manipulation', $wizardData), 'data-severity' => 'notice', 'data-image-name' => $file->getNameWithoutExtension(), 'data-image-uid' => $file->getUid(), 'data-file-field' => $config['file_field'], 'data-field' => $formFieldId);
$button = '<button class="btn btn-default t3js-image-manipulation-trigger"';
foreach ($buttonAttributes as $key => $value) {
$button .= ' ' . $key . '="' . htmlspecialchars($value) . '"';
}
$button .= '><span class="t3-icon fa fa-crop"></span>';
$button .= $languageService->sL('LLL:EXT:lang/locallang_wizards.xlf:imwizard.open-editor', true);
$button .= '</button>';
$inputField = '<input type="hidden" ' . 'id="' . $formFieldId . '" ' . 'name="' . $parameterArray['itemFormElName'] . '" ' . 'value="' . htmlspecialchars($parameterArray['itemFormElValue']) . '" />';
$content .= $inputField . $button;
$content .= $this->getImageManipulationInfoTable($parameterArray['itemFormElValue']);
$resultArray['requireJsModules'][] = array('TYPO3/CMS/Backend/ImageManipulation' => 'function(ImageManipulation){ImageManipulation.initializeTrigger()}');
}
$content .= '<p class="text-muted"><em>' . $languageService->sL('LLL:EXT:lang/locallang_wizards.xlf:imwizard.supported-types-message', true) . '<br />';
$content .= mb_strtoupper(implode(', ', GeneralUtility::trimExplode(',', $config['allowedExtensions'])));
$content .= '</em></p>';
$item = '<div class="media">';
$item .= $preview;
$item .= '<div class="media-body">' . $content . '</div>';
$item .= '</div>';
$resultArray['html'] = $item;
return $resultArray;
}
示例4: tearDown
/**
* Unset all additional properties of test classes to help PHP
* garbage collection. This reduces memory footprint with lots
* of tests.
*
* If owerwriting tearDown() in test classes, please call
* parent::tearDown() at the end. Unsetting of own properties
* is not needed this way.
*
* @throws \RuntimeException
* @return void
*/
protected function tearDown()
{
// Unset properties of test classes to safe memory
$reflection = new \ReflectionObject($this);
foreach ($reflection->getProperties() as $property) {
$declaringClass = $property->getDeclaringClass()->getName();
if (!$property->isStatic() && $declaringClass !== \TYPO3\CMS\Core\Tests\UnitTestCase::class && $declaringClass !== \TYPO3\CMS\Core\Tests\BaseTestCase::class && strpos($property->getDeclaringClass()->getName(), 'PHPUnit_') !== 0) {
$propertyName = $property->getName();
unset($this->{$propertyName});
}
}
unset($reflection);
// Delete registered test files and directories
foreach ($this->testFilesToDelete as $absoluteFileName) {
$absoluteFileName = GeneralUtility::fixWindowsFilePath(PathUtility::getCanonicalPath($absoluteFileName));
if (!GeneralUtility::validPathStr($absoluteFileName)) {
throw new \RuntimeException('tearDown() cleanup: Filename contains illegal characters', 1410633087);
}
if (!StringUtility::beginsWith($absoluteFileName, PATH_site . 'typo3temp/')) {
throw new \RuntimeException('tearDown() cleanup: Files to delete must be within typo3temp/', 1410633412);
}
// file_exists returns false for links pointing to not existing targets, so handle links before next check.
if (@is_link($absoluteFileName) || @is_file($absoluteFileName)) {
unlink($absoluteFileName);
} elseif (@is_dir($absoluteFileName)) {
GeneralUtility::rmdir($absoluteFileName, true);
} else {
throw new \RuntimeException('tearDown() cleanup: File, link or directory does not exist', 1410633510);
}
}
$this->testFilesToDelete = array();
}
示例5: render
/**
* @param array|NULL $backendUser
* @param int $size
* @param bool $showIcon
* @return string
*/
public function render(array $backendUser = NULL, $size = 32, $showIcon = FALSE)
{
$size = (int) $size;
if (!is_array($backendUser)) {
$backendUser = $this->getBackendUser()->user;
}
$image = parent::render($backendUser, $size, $showIcon);
if (!StringUtility::beginsWith($image, '<span class="avatar"><span class="avatar-image"></span>') || empty($backendUser['email'])) {
return $image;
}
$cachedFilePath = PATH_site . 'typo3temp/t3gravatar/';
$cachedFileName = sha1($backendUser['email'] . $size) . '.jpg';
if (!file_exists($cachedFilePath . $cachedFileName)) {
$gravatar = 'https://www.gravatar.com/avatar/' . md5(strtolower($backendUser['email'])) . '?s=' . $size . '&d=404';
$gravatarImage = GeneralUtility::getUrl($gravatar);
if (empty($gravatarImage)) {
return $image;
}
GeneralUtility::writeFileToTypo3tempDir($cachedFileName, $gravatarImage);
}
// Icon
$icon = '';
if ($showIcon) {
$icon = '<span class="avatar-icon">' . IconUtility::getSpriteIconForRecord('be_users', $backendUser) . '</span>';
}
$relativeFilePath = PathUtility::getRelativePath(PATH_typo3, $cachedFilePath);
return '<span class="avatar"><span class="avatar-image">' . '<img src="' . $relativeFilePath . $cachedFileName . '" width="' . $size . '" height="' . $size . '" /></span>' . $icon . '</span>';
}
示例6: addData
/**
* Resolve placeholders for input/text fields. Placeholders that are simple
* strings will be returned unmodified. Placeholders beginning with __row are
* being resolved, possibly traversing multiple tables.
*
* @param array $result
* @return array
*/
public function addData(array $result)
{
foreach ($result['processedTca']['columns'] as $fieldName => $fieldConfig) {
// Placeholders are only valid for input and text type fields
if ($fieldConfig['config']['type'] !== 'input' && $fieldConfig['config']['type'] !== 'text' || !isset($fieldConfig['config']['placeholder'])) {
continue;
}
// Resolve __row|field type placeholders
if (StringUtility::beginsWith($fieldConfig['config']['placeholder'], '__row|')) {
// split field names into array and remove the __row indicator
$fieldNameArray = array_slice(GeneralUtility::trimExplode('|', $fieldConfig['config']['placeholder'], true), 1);
$result['processedTca']['columns'][$fieldName]['config']['placeholder'] = $this->getPlaceholderValue($fieldNameArray, $result);
}
// Resolve placeholders from language files
if (StringUtility::beginsWith($fieldConfig['config']['placeholder'], 'LLL:')) {
$result['processedTca']['columns'][$fieldName]['config']['placeholder'] = $this->getLanguageService()->sl($fieldConfig['config']['placeholder']);
}
// Remove empty placeholders
if (empty($fieldConfig['config']['placeholder'])) {
unset($result['processedTca']['columns'][$fieldName]['config']['placeholder']);
continue;
}
}
return $result;
}
示例7: render
/**
* Rendering the cObject, QTOBJECT
*
* @param array $conf Array of TypoScript properties
* @return string Output
*/
public function render($conf = array())
{
$params = $prefix = '';
if ($GLOBALS['TSFE']->baseUrl) {
$prefix = $GLOBALS['TSFE']->baseUrl;
}
if ($GLOBALS['TSFE']->absRefPrefix) {
$prefix = $GLOBALS['TSFE']->absRefPrefix;
}
$type = isset($conf['type.']) ? $this->cObj->stdWrap($conf['type'], $conf['type.']) : $conf['type'];
// If file is audio and an explicit path has not been set,
// take path from audio fallback property
if ($type == 'audio' && empty($conf['file'])) {
$conf['file'] = $conf['audioFallback'];
}
$filename = isset($conf['file.']) ? $this->cObj->stdWrap($conf['file'], $conf['file.']) : $conf['file'];
$typeConf = $conf[$type . '.'];
// Add QTobject js-file
$this->getPageRenderer()->addJsFile($this->getPathToLibrary('flashmedia/qtobject/qtobject.js'));
$replaceElementIdString = StringUtility::getUniqueId('mmqt');
$GLOBALS['TSFE']->register['MMQTID'] = $replaceElementIdString;
$qtObject = 'QTObject' . $replaceElementIdString;
// Merge with default parameters
$conf['params.'] = array_merge((array) $typeConf['default.']['params.'], (array) $conf['params.']);
if (is_array($conf['params.']) && is_array($typeConf['mapping.']['params.'])) {
ArrayUtility::remapArrayKeys($conf['params.'], $typeConf['mapping.']['params.']);
foreach ($conf['params.'] as $key => $value) {
$params .= $qtObject . '.addParam("' . $key . '", "' . $value . '");' . LF;
}
}
$params = ($params ? substr($params, 0, -2) : '') . LF . $qtObject . '.write("' . $replaceElementIdString . '");';
$alternativeContent = isset($conf['alternativeContent.']) ? $this->cObj->stdWrap($conf['alternativeContent'], $conf['alternativeContent.']) : $conf['alternativeContent'];
$layout = str_replace(array('###ID###', '###QTOBJECT###'), array($replaceElementIdString, '<div id="' . $replaceElementIdString . '">' . $alternativeContent . '</div>'), isset($conf['layout.']) ? $this->cObj->stdWrap($conf['layout'], $conf['layout.']) : $conf['layout']);
$width = isset($conf['width.']) ? $this->cObj->stdWrap($conf['width'], $conf['width.']) : $conf['width'];
if (!$width) {
$width = $conf[$type . '.']['defaultWidth'];
}
$height = isset($conf['height.']) ? $this->cObj->stdWrap($conf['height'], $conf['height.']) : $conf['height'];
if (!$height) {
$height = $conf[$type . '.']['defaultHeight'];
}
$fullFilename = $filename;
// If the file name doesn't contain a scheme, prefix with appropriate data
if (strpos($filename, '://') === false && !empty($prefix)) {
$fullFilename = $prefix . $filename;
}
$embed = 'var ' . $qtObject . ' = new QTObject("' . $fullFilename . '", "' . $replaceElementIdString . '", "' . $width . '", "' . $height . '");';
$content = $layout . '
<script type="text/javascript">
' . $embed . '
' . $params . '
</script>';
if (isset($conf['stdWrap.'])) {
$content = $this->cObj->stdWrap($content, $conf['stdWrap.']);
}
return $content;
}
示例8: generateInlineMarkup
/**
* @param Icon $icon
* @param array $options
* @return string
* @throws \InvalidArgumentException
*/
protected function generateInlineMarkup(Icon $icon, array $options)
{
if (empty($options['source'])) {
throw new \InvalidArgumentException('The option "source" is required and must not be empty', 1440754980);
}
$source = $options['source'];
if (StringUtility::beginsWith($source, 'EXT:') || !StringUtility::beginsWith($source, '/')) {
$source = GeneralUtility::getFileAbsFileName($source);
}
return $this->getInlineSvg($source);
}
示例9: generateMarkup
/**
* @param Icon $icon
* @param array $options
* @return string
* @throws \InvalidArgumentException
*/
protected function generateMarkup(Icon $icon, array $options)
{
if (empty($options['source'])) {
throw new \InvalidArgumentException('[' . $icon->getIdentifier() . '] The option "source" is required and must not be empty', 1440754980);
}
$source = $options['source'];
if (StringUtility::beginsWith($source, 'EXT:') || !StringUtility::beginsWith($source, '/')) {
$source = GeneralUtility::getFileAbsFileName($source);
}
$source = PathUtility::getAbsoluteWebPath($source);
return '<img src="' . htmlspecialchars($source) . '" width="' . $icon->getDimension()->getWidth() . '" height="' . $icon->getDimension()->getHeight() . '" />';
}
示例10: addData
/**
* Initialize new row with unique uid
*
* @param array $result
* @return array
* @throws \InvalidArgumentException
*/
public function addData(array $result)
{
if ($result['command'] !== 'new') {
return $result;
}
// Throw exception if uid is already set
if (isset($result['databaseRow']['uid'])) {
throw new \InvalidArgumentException('uid is already set to ' . $result['databaseRow']['uid'], 1437991120);
}
$result['databaseRow']['uid'] = StringUtility::getUniqueId('NEW');
return $result;
}
示例11: addTcaTypeIcon
/**
* Add the given icon to the TCA table type
*
* @param string $table
* @param string $type
* @param string $icon
*/
public static function addTcaTypeIcon($table, $type, $icon)
{
if (GeneralUtility::compat_version('7.0')) {
$fullIconPath = substr(PathUtility::getAbsoluteWebPath($icon), 1);
if (StringUtility::endsWith(strtolower($fullIconPath), 'svg')) {
$iconProviderClass = 'TYPO3\\CMS\\Core\\Imaging\\IconProvider\\SvgIconProvider';
} else {
$iconProviderClass = 'TYPO3\\CMS\\Core\\Imaging\\IconProvider\\BitmapIconProvider';
}
/** @var IconRegistry $iconRegistry */
$iconRegistry = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Imaging\\IconRegistry');
$iconIdentifier = 'tcarecords-' . $table . '-' . $type;
$iconRegistry->registerIcon($iconIdentifier, $iconProviderClass, ['source' => $fullIconPath]);
$GLOBALS['TCA']['tt_content']['ctrl']['typeicon_classes'][$type] = $iconIdentifier;
} else {
$fullIconPath = str_replace('../typo3/', '', $icon);
SpriteManager::addTcaTypeIcon('tt_content', $type, $fullIconPath);
}
}
示例12: getNativeDefaultValue
/**
* Return the default value of a field formatted to match the native MySQL SQL dialect
*
* @param array $fieldDefinition
* @return mixed
*/
protected function getNativeDefaultValue($fieldDefinition)
{
if (!$fieldDefinition['has_default']) {
$returnValue = null;
} elseif ($fieldDefinition['type'] === 'SERIAL' && substr($fieldDefinition['default_value'], 0, 7) === 'nextval') {
$returnValue = null;
} elseif ($fieldDefinition['type'] === 'varchar') {
// Strip character class and unquote string
if (StringUtility::beginsWith($fieldDefinition['default_value'], 'NULL::')) {
$returnValue = null;
} else {
$returnValue = str_replace("\\'", "'", preg_replace('/\'(.*)\'(::(?:character\\svarying|varchar|character|char|text)(?:\\(\\d+\\))?)?\\z/', '\\1', $fieldDefinition['default_value']));
}
} elseif (substr($fieldDefinition['type'], 0, 3) === 'int') {
$returnValue = (int) preg_replace('/^\\(?(\\-?\\d+)\\)?$/', '\\1', $fieldDefinition['default_value']);
} else {
$returnValue = $fieldDefinition['default_value'];
}
return $returnValue;
}
示例13: decryptDataArray
/**
* @param array $data
* @return array
*/
protected function decryptDataArray(array $data)
{
foreach ($data as $key => $value) {
if (empty($value)) {
continue;
}
if (is_array($value)) {
$data[$key] = $this->decryptDataArray($value);
continue;
}
if (!StringUtility::beginsWith($value, 'rsa:')) {
continue;
}
$decryptedValue = $this->getBackend()->decrypt($this->getKey(), substr($value, 4));
if ($decryptedValue !== null) {
$data[$key] = $decryptedValue;
}
}
return $data;
}
示例14: addData
/**
* Determine which fields are required to render the placeholders and
* add those to the list of columns that must be processed by the next
* data providers.
*
* @param array $result
* @return array
*/
public function addData(array $result)
{
foreach ($result['processedTca']['columns'] as $fieldName => $fieldConfig) {
// Placeholders are only valid for input and text type fields
if ($fieldConfig['config']['type'] !== 'input' && $fieldConfig['config']['type'] !== 'text' || !isset($fieldConfig['config']['placeholder'])) {
continue;
}
// Process __row|field type placeholders
if (StringUtility::beginsWith($fieldConfig['config']['placeholder'], '__row|')) {
// split field names into array and remove the __row indicator
$fieldNameArray = array_slice(GeneralUtility::trimExplode('|', $fieldConfig['config']['placeholder'], true), 1);
// only the first field is required to be processed as it's the one referring to
// the current record. All other columns will be resolved in a later pass through
// the related records.
if (!empty($fieldNameArray[0])) {
$result['columnsToProcess'][] = $fieldNameArray[0];
}
}
}
return $result;
}
示例15: process
/**
* Generates the JumpURL for the given parameters.
*
* @see \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer::processUrlModifiers()
* @param string $context The context in which the URL is generated (e.g. "typolink").
* @param string $url The URL that should be processed.
* @param array $configuration The link configuration.
* @param \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer $contentObjectRenderer The calling content object renderer.
* @param bool $keepProcessing If this is set to FALSE no further hooks will be processed after the current one.
* @return string
*/
public function process($context, $url, array $configuration, ContentObjectRenderer $contentObjectRenderer, &$keepProcessing)
{
if (!$this->isEnabled($context, $configuration)) {
return $url;
}
$this->contentObjectRenderer = $contentObjectRenderer;
// Strip the absRefPrefix from the URLs.
$urlPrefix = (string) $this->getTypoScriptFrontendController()->absRefPrefix;
if ($urlPrefix !== '' && StringUtility::beginsWith($url, $urlPrefix)) {
$url = substr($url, strlen($urlPrefix));
}
// Make sure the slashes in the file URL are not encoded.
if ($context === UrlProcessorInterface::CONTEXT_FILE) {
$url = str_replace('%2F', '/', rawurlencode(rawurldecode($url)));
}
$url = $this->build($url, isset($configuration['jumpurl.']) ? $configuration['jumpurl.'] : array());
// Now add the prefix again if it was not added by a typolink call already.
if ($urlPrefix !== '' && !StringUtility::beginsWith($url, $urlPrefix)) {
$url = $urlPrefix . $url;
}
return $url;
}