/** * Render a node label * * @param NodeInterface $node * @param boolean $crop This argument is deprecated as of Neos 1.2 and will be removed. Don't rely on this behavior and crop labels in the view. * @return string */ public function getLabel(NodeInterface $node, $crop = true) { $label = \TYPO3\Eel\Utility::evaluateEelExpression($this->getExpression(), $this->eelEvaluator, array('node' => $node), $this->defaultContextConfiguration); if ($crop === false) { return $label; } $croppedLabel = \TYPO3\Flow\Utility\Unicode\Functions::substr($label, 0, 30); return $croppedLabel . (strlen($croppedLabel) < strlen($label) ? ' …' : ''); }
/** * Returns a random string with alpha-numeric characters. * * @param integer $count Number of characters to generate * @param string $characters Allowed characters, defaults to alpha-numeric (a-zA-Z0-9) * @return string A random string */ public static function generateRandomString($count, $characters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789') { $characterCount = \TYPO3\Flow\Utility\Unicode\Functions::strlen($characters); $string = ''; for ($i = 0; $i < $count; $i++) { $string .= \TYPO3\Flow\Utility\Unicode\Functions::substr($characters, random_int(0, $characterCount - 1), 1); } return $string; }
/** * @param array $arguments * @param callable $renderChildrenClosure * @param \TYPO3\Fluid\Core\Rendering\RenderingContextInterface $renderingContext * @return string */ public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext) { $value = $arguments['value']; if ($value === null) { $value = $renderChildrenClosure(); } if (UnicodeUtilityFunctions::strlen($value) > $arguments['maxCharacters']) { return UnicodeUtilityFunctions::substr($value, 0, $arguments['maxCharacters']) . $arguments['append']; } return $value; }
/** * Render a node label * * @param \TYPO3\TYPO3CR\Domain\Model\AbstractNodeData $nodeData * @param boolean $crop This argument is deprecated as of Neos 1.2 and will be removed. Don't rely on this behavior and crop labels in the view. * @return string */ public function getLabel(AbstractNodeData $nodeData, $crop = true) { if ($nodeData->hasProperty('title') === true && $nodeData->getProperty('title') !== '') { $label = strip_tags($nodeData->getProperty('title')); } elseif ($nodeData->hasProperty('text') === true && $nodeData->getProperty('text') !== '') { $label = strip_tags($nodeData->getProperty('text')); } else { $label = ($nodeData->getNodeType()->getLabel() ?: $nodeData->getNodeType()->getName()) . ' (' . $nodeData->getName() . ')'; } if ($crop === false) { return $label; } $croppedLabel = \TYPO3\Flow\Utility\Unicode\Functions::substr($label, 0, 30); return $croppedLabel . (strlen($croppedLabel) < strlen($label) ? ' …' : ''); }
/** * Render a node label * * @param \TYPO3\TYPO3CR\Domain\Model\AbstractNodeData $nodeData * @param boolean $crop * @return string */ public function getLabel(AbstractNodeData $nodeData, $crop = TRUE) { if ($nodeData->hasProperty('title') === TRUE && $nodeData->getProperty('title') !== '') { $label = strip_tags($nodeData->getProperty('title')); } elseif ($nodeData->hasProperty('text') === TRUE && $nodeData->getProperty('text') !== '') { $label = strip_tags($nodeData->getProperty('text')); } else { $label = ($nodeData->getNodeType()->getLabel() ?: $nodeData->getNodeType()->getName()) . ' (' . $nodeData->getName() . ')'; } if ($crop === FALSE) { return $label; } $croppedLabel = \TYPO3\Flow\Utility\Unicode\Functions::substr($label, 0, NodeInterface::LABEL_MAXIMUM_CHARACTERS); return $croppedLabel . (strlen($croppedLabel) < strlen($label) ? ' …' : ''); }
/** * Crop a string to ``maximumCharacters`` length, taking sentences into account, * optionally appending ``suffix`` if cropping was necessary. * * @param string $string The input string * @param integer $maximumCharacters Number of characters where cropping should happen * @param string $suffix Suffix to be appended if cropping was necessary * @return string The cropped string */ public function cropAtSentence($string, $maximumCharacters, $suffix = '') { if (UnicodeFunctions::strlen($string) > $maximumCharacters) { $iterator = new TextIterator($string, TextIterator::SENTENCE); $string = UnicodeFunctions::substr($string, 0, $iterator->preceding($maximumCharacters)); $string .= $suffix; } return $string; }
/** * Converts a (simple) YAML file to Python instructions. * * Note: First tried to use 3rd party libraries: * - spyc: http://code.google.com/p/spyc/ * - Symfony2 YAML: http://symfony.com/doc/current/components/yaml/introduction.html * but none of them were able to parse our Settings.yml Sphinx configuration files. * * @param string $filename Absolute filename to Settings.yml * @return string Python instruction set */ public function yamlToPython($filename) { $contents = file_get_contents($filename); $lines = explode(PHP_EOL, $contents); $pythonConfiguration = array(); $i = 0; while ($lines[$i] !== 'conf.py:' && $i < count($lines)) { $i++; } while ($i < count($lines)) { if (preg_match('/^(\\s+)([^:]+):\\s*(.*)$/', $lines[$i], $matches)) { switch ($matches[2]) { case 'latex_documents': $pythonLine = 'latex_documents = [(' . PHP_EOL; if (preg_match('/^(\\s+)- - /', $lines[$i + 1], $matches)) { $indent = $matches[1]; $firstLine = TRUE; while (preg_match('/^' . $indent . '(- -| -) (.+)$/', $lines[++$i], $matches)) { if (!$firstLine) { $pythonLine .= ',' . PHP_EOL; } $pythonLine .= sprintf('u\'%s\'', addcslashes($matches[2], "\\'")); $firstLine = FALSE; } } $pythonLine .= PHP_EOL . ')]'; $i--; break; case 'latex_elements': $pythonLine = 'latex_elements = {' . PHP_EOL; if (preg_match('/^(\\s+)/', $lines[$i + 1], $matches)) { $indent = $matches[1]; $firstLine = TRUE; while (preg_match('/^' . $indent . '([^:]+):\\s*(.*)$/', $lines[++$i], $matches)) { if (!$firstLine) { $pythonLine .= ',' . PHP_EOL; } $pythonLine .= sprintf('\'%s\': \'%s\'', $matches[1], addcslashes($matches[2], "\\'")); $firstLine = FALSE; } } $pythonLine .= PHP_EOL . '}'; $i--; break; case 'extensions': $pythonLine = 'extensions = ['; if (preg_match('/^(\\s+)/', $lines[$i + 1], $matches)) { $indent = $matches[1]; $firstItem = TRUE; while (preg_match('/^' . $indent . '- (.+)/', $lines[++$i], $matches)) { if (Functions::substr($matches[1], 0, 9) === 't3sphinx.') { // Extension t3sphinx is not compatible with JSON output continue; } if (!$firstItem) { $pythonLine .= ', '; } $pythonLine .= sprintf('\'%s\'', $matches[1]); $firstItem = FALSE; } $i--; } $pythonLine .= ']'; break; case 'intersphinx_mapping': $pythonLine = 'intersphinx_mapping = {' . PHP_EOL; if (preg_match('/^(\\s+)/', $lines[$i + 1], $matches)) { $indent = $matches[1]; $firstLine = TRUE; while (preg_match('/^' . $indent . '(.+):/', $lines[++$i], $matches)) { if (!$firstLine) { $pythonLine .= ',' . PHP_EOL; } $pythonLine .= sprintf('\'%s\': (', $matches[1]); $firstItem = TRUE; while (preg_match('/^' . $indent . '- (.+)/', $lines[++$i], $matches)) { if (!$firstItem) { $pythonLine .= ', '; } if ($matches[1] === 'null') { $pythonLine .= 'None'; } else { $pythonLine .= sprintf('\'%s\'', $matches[1]); } $firstItem = FALSE; } $pythonLine .= ')'; $firstLine = FALSE; $i--; } } $pythonLine .= PHP_EOL . '}'; $i--; break; default: $pythonLine = sprintf('%s = u\'%s\'', $matches[2], addcslashes($matches[3], "\\'")); break; } if (!empty($pythonLine)) { $pythonConfiguration[] = $pythonLine; } } $i++; } return $pythonConfiguration; }
/** * Checks if substr() can handle UTF8 strings, specifying no length * * @test */ public function substrWorksWithUTF8CharactersSpecifyingNoLength() { $testString = 'Kasper Skårhøj implemented most versions of TYPO3.'; $this->assertEquals('implemented most versions of TYPO3.', Functions::substr($testString, 15), 'substr() with UTF8 characters did not return the expected string after specifying no length.'); }