/** * Pimple callback register render. * * @param $render * @param string $ns * @return \Closure */ private static function _register($render, $ns) { return function () use($render, $ns) { $render = Str::clean($render); $render = implode('\\', array($ns, Html::RENDER_DIR, ucfirst($render))); return new $render(); }; }
/** * Clear string classes. * * @param string $classes * @return string */ protected function _clearClasses($classes) { $newClasses = []; $details = explode(' ', $classes); foreach ($details as $class) { if (empty($class)) { continue; } $newClasses[] = Str::slug(Str::clean($class)); } return implode(' ', $newClasses); }
/** * Create img tag. * * @param string $src * @param string|array $class * @param string $id * @param array $attrs * @return string */ public function render($src, $class = '', $id = '', array $attrs = array()) { $attrs['class'] = false; $attrs = array_merge(array('fullUrl' => true), $attrs); $attrs['id'] = $id; $attrs = $this->_normalizeClassAttr($attrs, $this->_jbSrt('image')); if ($class !== '') { $attrs = $this->_normalizeClassAttr($attrs, $class); } $attrs['class'] = Str::clean($attrs['class']); $isFull = $attrs['fullUrl']; unset($attrs['fullUrl']); $src = FS::clean($src, '/'); $attrs['src'] = $isFull ? Url::root() . '/' . $src : $src; return '<img ' . $this->buildAttrs($attrs) . ' />'; }
/** * {@inheritdoc} */ public function request($url, $args = array(), array $options = array()) { $result = null; // Merge with default $options = array_merge($this->_defaultOptions, (array) $options); $options = new Data($options); // Prepare options for request $args = is_string($args) ? $args : (array) $args; $timeout = (int) $options->get('timeout'); $isDebug = (int) $options->get('debug'); $sslVerify = (int) $options->get('ssl_verify'); $headers = (array) $options->get('headers'); $userAgent = trim($options->get('user_agent')); $resultType = Str::clean($options->get('response'), true); // Prepare options for cache $isCache = (int) $options->get('cache'); $cacheTTL = (int) $options->get('cache_ttl'); $cacheId = array('url' => $url, 'data' => $args, 'options' => $options->getArrayCopy()); try { // Check cache if ($isCache && ($result = $this->_cms['cache']->get($cacheId, self::CACHE_GROUP))) { return $result; } $method = $this->_getMethod($options->get('method')); // Add args to url for GET methods if (self::METHOD_GET === $method) { $url = Url::addArg($args, $url); $args = array(); } // Request via CMS API $apiResp = $this->_request($url, $args, new Data(array('timeout' => $timeout, 'headers' => $headers, 'method' => $method, 'debug' => $isDebug, 'user_agent' => $userAgent, 'ssl_verify' => $sslVerify))); } catch (\Exception $e) { $apiResp = new Data(array('body' => 'CrossCMS Error: ' . $e->getMessage() . PHP_EOL . PHP_EOL . $e->getTraceAsString(), 'headers' => array(), 'code' => 0)); } // Prepare response format $response = $this->_compactResponse($apiResp); $result = $this->_getResultByType($response, $resultType); // Store to cache if ($isCache && null !== $result) { $this->_cms['cache']->set($cacheId, $result, self::CACHE_GROUP, true, $cacheTTL); } return $result; }
/** * @param $string * @return string */ public static function clean($string) { return Str::clean($string, true, true); }
public function testClean() { $input = ' <b>ASDF</b> !@#$%^&*()_+"\';:>< '; isSame('ASDF !@#$%^&*()_+"\';:><', Str::clean($input)); isSame('asdf !@#$%^&*()_+\\"\\\';:><', Str::clean($input, true, true)); }