/** * Use markup for text. * * @package FeM\sPof\template\smartyPlugins * @author dangerground * @since 1.0 * * @api * * @param string $string * @param bool $tohtml (optional) * @param bool $convertmarkup (optional) * @param bool $nl2br (optional) * @param bool $marklinks (optional) * @param int $hstart (optional) headline to start with * * @return string */ function smarty_modifier_markup2html($string, $tohtml = true, $convertmarkup = true, $nl2br = true, $marklinks = true, $hstart = 4) { $out = $string; // split text for non-markup texts $codes = preg_split('#(%%|</?code>)#mi', $out, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE); $usemarkup = true; foreach ($codes as &$code) { // handle nowiki text if ($code === '%%') { if ($usemarkup) { $code = ''; $usemarkup = false; continue; } else { $code = ''; $usemarkup = true; continue; } } elseif ($code === '<code>') { // do not apply markup formatting $code = '<pre><code>'; $usemarkup = false; continue; } elseif ($code === '</code>') { // start to apply markup again $code = '</code></pre>'; $usemarkup = true; continue; } // format text if ($usemarkup) { $code = \FeM\sPof\StringUtil::markup2html($code, $tohtml, $convertmarkup, $nl2br, $marklinks, $hstart); } else { $code = \FeM\sPof\StringUtil::markup2html($code, true, false, false); } } return implode('', $codes); }
/** * Escape the string using base64 with the little addition, that a dot is used instead of the slash, makes it usable * for urls. * * @package FeM\sPof\template\smartyPlugins * @author dangerground * @since 1.0 * * @api * * @param string $text * * @return string */ function smarty_modifier_pbase64_encode($text) { return \FeM\sPof\StringUtil::pbase64Encode($text); }
/** * This function returns a url based on the route name and the arguments which are filled in the url pattern. * * @api * * @throws \InvalidArgumentException * * @param string $name route name * @param array $arguments (optional) arguments which replace the placeholder in the url pattern * * @return string */ public static function reverse($name, array $arguments = []) { static $routes; if ($routes === null) { $routes = self::getRoutes(); } // check if the routes.yml was parsed correctly, if not, stop debugspam here if (empty($routes)) { return ''; } // if we have no name, so throw arguments of the if (empty($name)) { Logger::getInstance()->error(_s('Missing URL Name, just got params: ') . var_export($arguments, true)); } // check for existing name if (!isset($routes[$name])) { Logger::getInstance()->error(_s('Could not find URL with name: "%s" and params in ', $name) . var_export($arguments, true)); return ''; } $pattern = $routes[$name]['pattern']; $suffix = isset($routes[$name]['optional_suffix']) ? $routes[$name]['optional_suffix'] : null; $prefix = isset($routes[$name]['optional_prefix']) ? $routes[$name]['optional_prefix'] : null; $patternOptional = rtrim($prefix . $pattern . $suffix, '/'); $patternSufOptional = rtrim($pattern . $suffix, '/'); $patternPreOptional = rtrim($prefix . $pattern, '/'); $pattern = rtrim($pattern, '/'); // replace placeholder with their value from arguments, use optional params as base, as it contains all params if (preg_match_all('/<([^>]+)>/S', $patternOptional, $matches, PREG_SET_ORDER)) { foreach ($matches as $match) { // skip non existing params if (!isset($arguments[$match[1]]) || $arguments[$match[1]] === null) { continue; } $pattern = str_replace('<' . $match[1] . '>', StringUtil::reduce($arguments[$match[1]]), $pattern); $patternOptional = str_replace('<' . $match[1] . '>', StringUtil::reduce($arguments[$match[1]]), $patternOptional); $patternSufOptional = str_replace('<' . $match[1] . '>', StringUtil::reduce($arguments[$match[1]]), $patternSufOptional); $patternPreOptional = str_replace('<' . $match[1] . '>', StringUtil::reduce($arguments[$match[1]]), $patternPreOptional); } } // check for remaining unresolved params if (strpos($pattern, '<')) { Logger::getInstance()->error(_s('Could not resolve all params in "%s": "%s". Arguments=%s', $name, $pattern, var_export($arguments, true))); } // check if all optional params are resolved, if not -> return normal path if (strpos($patternOptional, '<') === false) { // optional params are resolved, so return full path return $patternOptional . (isset($arguments['_anchor']) ? '#' . $arguments['_anchor'] : ''); } elseif (strpos($patternPreOptional, '<') === false) { return $patternPreOptional . (isset($arguments['_anchor']) ? '#' . $arguments['_anchor'] : ''); } elseif (strpos($patternSufOptional, '<') === false) { // optional params are resolved, so return full path return $patternSufOptional . (isset($arguments['_anchor']) ? '#' . $arguments['_anchor'] : ''); } else { // join parts together return $pattern . (isset($arguments['_anchor']) ? '#' . $arguments['_anchor'] : ''); } }