/** * Creates a slug based on a given string. * * @param string $str * * @return string */ public static function createSlug($str) { // Remove HTML tags $str = StringHelper::stripHtml($str); // Convert to kebab case $glue = craft()->config->get('slugWordSeparator'); $lower = !craft()->config->get('allowUppercaseInSlug'); $str = StringHelper::toKebabCase($str, $glue, $lower, false); return $str; }
/** * @inheritDoc IPreviewableFieldType::getTableAttributeHtml() * * @param mixed $value * * @return string */ public function getTableAttributeHtml($value) { $value = (string) $value; return StringHelper::stripHtml($value); }
/** * 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()); }