public function testInputArrayTagCss() { $testStr = array(array('string' => 'der erste string', 'tag' => 'span', 'cssClass' => 'foo'), array('string' => ' - ein zweiter str', 'tag' => 'div', 'cssClass' => 'bar')); $h = new Kwf_View_Helper_Truncate(); $this->assertEquals('<span class="foo">der erste st...</span>', $h->truncate($testStr, 15, '...', true)); $this->assertEquals('<span class="foo">der erste string</span><div class="bar">...</div>', $h->truncate($testStr, 19, '...', true)); $this->assertEquals('<span class="foo">der erste string</span><div class="bar"> - ein zw...</div>', $h->truncate($testStr, 28, '...', true)); $this->assertEquals('<span class="foo">der erste string</span><div class="bar"> - ein zweiter str</div>', $h->truncate($testStr, 100, '...', true)); }
public static function replaceCodes($content) { // html entfernen $content = htmlspecialchars($content); // smileys $content = preg_replace('/:-?\\)/', '<img src="/assets/silkicons/emoticon_smile.png" alt=":-)" />', $content); $content = preg_replace('/:-?D/', '<img src="/assets/silkicons/emoticon_grin.png" alt=":-D" />', $content); $content = preg_replace('/:-?P/', '<img src="/assets/silkicons/emoticon_tongue.png" alt=":-P" />', $content); $content = preg_replace('/:-?\\(/', '<img src="/assets/silkicons/emoticon_unhappy.png" alt=":-(" />', $content); $content = preg_replace('/;-?\\)/', '<img src="/assets/silkicons/emoticon_wink.png" alt=";-)" />', $content); // zitate $content = str_replace('[quote]', '<fieldset class="quote"><legend>Zitat</legend>', $content, $countOpened); $content = preg_replace('/\\[quote=([^\\]]*)\\]/i', '<fieldset class="quote"><legend>Zitat von $1</legend>', $content, -1, $countOpenedPreg); $content = str_replace('[/quote]', '</fieldset>', $content, $closed); $open = $countOpened + $countOpenedPreg; while ($open > $closed) { $content .= '</fieldset>'; $closed++; } while ($closed > $open) { $content = '<fieldset class="quote"><legend>Zitat</legend>' . $content; $open++; } // automatische verlinkung $truncate = new Kwf_View_Helper_Truncate(); $pattern = '/((https?:\\/\\/www\\.)|(https?:\\/\\/)|(www\\.)){1,1}([a-z0-9äöü;\\/?:@=&!*~#%\'+$.,_-]+)/i'; $offset = 0; while (preg_match($pattern, $content, $matches, PREG_OFFSET_CAPTURE, $offset)) { if (!preg_match('/^http/', $matches[1][0])) { $matches[1][0] = 'http://' . $matches[1][0]; } $showUrl = preg_replace('/https?:\\/\\//', '', $matches[1][0]) . $truncate->truncate($matches[5][0], 60, '...', true); $replace = "<a href=\"{$matches[1][0]}{$matches[5][0]}\" " . "title=\"{$matches[1][0]}{$matches[5][0]}\" data-kwc-popup=\"blank\">{$showUrl}</a>"; $content = substr($content, 0, $matches[0][1]) . $replace . substr($content, $matches[0][1] + strlen($matches[0][0])); $offset = $matches[0][1] + strlen($replace); } return nl2br($content); }
public function componentToString(Kwf_Component_Data $data) { $truncate = new Kwf_View_Helper_Truncate(); $ret = $truncate->truncate($data->getComponent()->getSearchContent(), 15); return $ret; }
protected function _createItemByRow($row) { $truncateHelper = new Kwf_View_Helper_Truncate(); $primaryKey = $this->_primaryKey; $r = array(); if (!isset($r[$primaryKey]) && isset($row->{$primaryKey})) { $r[$primaryKey] = $row->{$primaryKey}; } if (!$this->_labelField && $row instanceof Kwf_Model_Row_Interface) { $r['label'] = $row->__toString(); } else { if ($this->_labelField) { $r['label'] = $row->{$this->_labelField}; } else { throw new Kwf_Exception("You have to set _labelField in the ImageGrid Controller"); } } if (!empty($r['label'])) { $r['label_short'] = $r['label']; } if (!empty($r['label_short']) && $this->_maxLabelLength) { $r['label_short'] = $truncateHelper->truncate($r['label_short'], $this->_maxLabelLength, '…', true, false); } $imageRef = $this->_getImageReference(); $hashKey = Kwf_Util_Hash::hash($row->{$imageRef['column']}); $r['src'] = '/kwf/media/upload/preview?uploadId=' . $row->{$imageRef['column']} . '&hashKey=' . $hashKey . '&size=imageGrid'; $r['src_large'] = '/kwf/media/upload/preview?uploadId=' . $row->{$imageRef['column']} . '&hashKey=' . $hashKey . '&size=imageGridLarge'; if ($uploadRow = $row->getParentRow($this->_imageRule)) { $dim = Kwf_Media_Image::calculateScaleDimensions($uploadRow->getFileSource(), array(400, 400, 'cover' => false)); $r['src_large_width'] = $dim['width']; $r['src_large_height'] = $dim['height']; } foreach ($this->_additionalDataFields as $f) { $r[$f] = $row->{$f}; } return $r; }