本文整理汇总了PHP中JString::strrpos方法的典型用法代码示例。如果您正苦于以下问题:PHP JString::strrpos方法的具体用法?PHP JString::strrpos怎么用?PHP JString::strrpos使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JString
的用法示例。
在下文中一共展示了JString::strrpos方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getFieldHTML
public function getFieldHTML($field, $required)
{
$required = $field->required == 1 ? ' data-required="true"' : '';
//a fix for wrong data
$field->value = JString::trim($field->value);
if (JString::strrpos($field->value, ',') == JString::strlen($field->value) - 1) {
$field->value = JString::substr($field->value, 0, -1);
}
$lists = explode(',', $field->value);
//CFactory::load( 'helpers' , 'string' );
$html = '<select id="field' . $field->id . '" name="field' . $field->id . '[]" type="select-multiple" multiple="multiple" class="joms-select joms-select--multiple" title="' . CStringHelper::escape(JText::_($field->tips)) . '" ' . $required . '>';
$elementSelected = 0;
foreach ($field->options as $option) {
$selected = in_array($option, $lists) ? ' selected="selected"' : '';
if (empty($selected)) {
$elementSelected++;
}
$html .= '<option value="' . $option . '"' . $selected . '>' . JText::_($option) . '</option>';
}
if ($elementSelected == 0) {
//if nothing is selected, we default the 1st option to be selected.
$elementName = 'field' . $field->id;
$html .= <<<HTML
<script type='text/javascript'>
var slt = document.getElementById('{$elementName}');
if(slt != null){
slt.options[0].selected = true;
}
</script>
HTML;
}
$html .= '</select>';
return $html;
}
示例2: truncate
/**
* Truncates text blocks over the specified character limit and closes
* all open HTML tags. The method will optionally not truncate an individual
* word, it will find the first space that is within the limit and
* truncate at that point. This method is UTF-8 safe.
*
* @param string $text The text to truncate.
* @param integer $length The maximum length of the text.
* @param boolean $noSplit Don't split a word if that is where the cutoff occurs (default: true).
* @param boolean $allowHtml Allow HTML tags in the output, and close any open tags (default: true).
*
* @return string The truncated text.
*
* @since 11.1
*/
public static function truncate($text, $length = 0, $noSplit = true, $allowHtml = true)
{
// Check if HTML tags are allowed.
if (!$allowHtml) {
// Deal with spacing issues in the input.
$text = str_replace('>', '> ', $text);
$text = str_replace(array(' ', ' '), ' ', $text);
$text = JString::trim(preg_replace('#\\s+#mui', ' ', $text));
// Strip the tags from the input and decode entities.
$text = strip_tags($text);
$text = html_entity_decode($text, ENT_QUOTES, 'UTF-8');
// Remove remaining extra spaces.
$text = str_replace(' ', ' ', $text);
$text = JString::trim(preg_replace('#\\s+#mui', ' ', $text));
}
// Truncate the item text if it is too long.
if ($length > 0 && JString::strlen($text) > $length) {
// Find the first space within the allowed length.
$tmp = JString::substr($text, 0, $length);
if ($noSplit) {
$offset = JString::strrpos($tmp, ' ');
if (JString::strrpos($tmp, '<') > JString::strrpos($tmp, '>')) {
$offset = JString::strrpos($tmp, '<');
}
$tmp = JString::substr($tmp, 0, $offset);
// If we don't have 3 characters of room, go to the second space within the limit.
if (JString::strlen($tmp) > $length - 3) {
$tmp = JString::substr($tmp, 0, JString::strrpos($tmp, ' '));
}
}
if ($allowHtml) {
// Put all opened tags into an array
preg_match_all("#<([a-z][a-z0-9]*)\\b.*?(?!/)>#i", $tmp, $result);
$openedTags = $result[1];
$openedTags = array_diff($openedTags, array("img", "hr", "br"));
$openedTags = array_values($openedTags);
// Put all closed tags into an array
preg_match_all("#</([a-z]+)>#iU", $tmp, $result);
$closedTags = $result[1];
$numOpened = count($openedTags);
// All tags are closed
if (count($closedTags) == $numOpened) {
return $tmp . '...';
}
$openedTags = array_reverse($openedTags);
// Close tags
for ($i = 0; $i < $numOpened; $i++) {
if (!in_array($openedTags[$i], $closedTags)) {
$tmp .= "</" . $openedTags[$i] . ">";
} else {
unset($closedTags[array_search($openedTags[$i], $closedTags)]);
}
}
}
$text = $tmp . '...';
}
return $text;
}
示例3: truncate
/**
* Truncates text blocks over the specified character limit and closes
* all open HTML tags. The behavior will not truncate an individual
* word, it will find the first space that is within the limit and
* truncate at that point. This method is UTF-8 safe.
*
* @param string $text The text to truncate.
* @param integer $length The maximum length of the text.
*
* @return string The truncated text.
*
* @since 11.1
*/
public static function truncate($text, $length = 0)
{
// Truncate the item text if it is too long.
if ($length > 0 && JString::strlen($text) > $length)
{
// Find the first space within the allowed length.
$tmp = JString::substr($text, 0, $length);
$offset = JString::strrpos($tmp, ' ');
if (JString::strrpos($tmp, '<') > JString::strrpos($tmp, '>'))
{
$offset = JString::strrpos($tmp, '<');
}
$tmp = JString::substr($tmp, 0, $offset);
// If we don't have 3 characters of room, go to the second space within the limit.
if (JString::strlen($tmp) >= $length - 3)
{
$tmp = JString::substr($tmp, 0, JString::strrpos($tmp, ' '));
}
// Put all opened tags into an array
preg_match_all("#<([a-z][a-z0-9]?)( .*)?(?!/)>#iU", $tmp, $result);
$openedtags = $result[1];
$openedtags = array_diff($openedtags, array("img", "hr", "br"));
$openedtags = array_values($openedtags);
// Put all closed tags into an array
preg_match_all("#</([a-z]+)>#iU", $tmp, $result);
$closedtags = $result[1];
$len_opened = count($openedtags);
// All tags are closed
if (count($closedtags) == $len_opened)
{
return $tmp . '...';
}
$openedtags = array_reverse($openedtags);
// Close tags
for ($i = 0; $i < $len_opened; $i++)
{
if (!in_array($openedtags[$i], $closedtags))
{
$tmp .= "</" . $openedtags[$i] . ">";
}
else
{
unset($closedtags[array_search($openedtags[$i], $closedtags)]);
}
}
$text = $tmp . '...';
}
return $text;
}
示例4: getFieldHTML
public function getFieldHTML($field, $required)
{
$lists = array();
//a fix for wrong data input
$field->value = JString::trim($field->value);
if (is_array($field->value)) {
$tmplist = $field->value;
} else {
if (JString::strrpos($field->value, ',') == JString::strlen($field->value) - 1) {
$field->value = JString::substr($field->value, 0, -1);
}
$tmplist = explode(',', $field->value);
}
if ($tmplist) {
foreach ($tmplist as $value) {
$lists[] = JString::trim($value);
}
}
$html = '';
$elementSelected = 0;
$elementCnt = 0;
$cnt = 0;
$params = new CParameter($field->params);
$readonly = '';
if ($params->get('readonly') == 1) {
$readonly = ' disabled="disabled"';
}
$html .= '<div style="display:inline-block">';
if (is_array($field->options)) {
foreach ($field->options as $option) {
if (JString::trim($option) == '') {
//do not display blank options
continue;
}
$selected = in_array(JString::trim($option), $lists) ? ' checked="checked"' : '';
if (empty($selected)) {
$elementSelected++;
}
$html .= '<label class="lblradio-block">';
$html .= '<input type="checkbox" name="field' . $field->id . '[]" value="' . $option . '" class="joms-checkbox" ' . $selected . $readonly . ' style="margin: 2px 5px 0 0" />';
$html .= JText::_($option) . '</label>';
$elementCnt++;
}
}
$html .= '</div>';
return $html;
}
示例5: crop
/**
* Crop string into given length.
* Method strip HTML tags and crop string to given length after last space.
* From croped string strip all characters which are not letter or number.
* At the end of string add tail according to language constant JOOMDOC_CROP.
*
* @param string $text string to crop
* @param int $length crop length
* @return string
*/
public static function crop($text, $length)
{
$chars = '~;!?.,@#$%^&*_-=+{}[]()<>:|"\'´`//\\';
$text = strip_tags($text);
$text = parent::trim($text);
if (parent::strlen($text) <= $length) {
return $text;
}
$text = parent::substr($text, 0, $length);
$lastSpace = parent::strrpos($text, ' ');
$text = parent::substr($text, 0, $lastSpace);
$text = parent::trim($text);
while ($length = parent::strlen($text)) {
$lastChar = parent::substr($text, $length - 2, 1);
if (parent::strpos($chars, $lastChar) !== false) {
$text = parent::substr($text, 0, $length - 1);
} else {
break;
}
}
return JText::sprintf('JOOMDOC_CROP', $text);
}
示例6: truncateText
protected static function truncateText($string, $limit)
{
$prevSpace = JString::strrpos(JString::substr($string, 0, $limit), ' ');
$prevLength = $prevSpace !== false ? $limit - max(0, $prevSpace) : $limit;
$nextSpace = JString::strpos($string, ' ', $limit + 1);
$nextLength = $nextSpace !== false ? max($nextSpace, $limit) - $limit : $limit;
$length = 0;
if ($prevSpace !== false && $nextSpace !== false) {
$length = $prevLength < $nextLength ? $prevSpace : $nextSpace;
} elseif ($prevSpace !== false && $nextSpace === false) {
$length = $length - $prevLength < $length * 0.1 ? $prevSpace : $length;
} elseif ($prevSpace === false && $nextSpace !== false) {
$length = $nextLength - $length < $length * 0.1 ? $nextSpace : $length;
}
if ($length > 0) {
$limit = $length;
}
$text = JString::substr($string, 0, $limit);
if (!preg_match('#(\\.|\\?|\\!)$#ismu', $text)) {
$text = preg_replace('#\\s?(\\,|\\;|\\:|\\-)$#ismu', '', $text) . ' ...';
}
return $text;
}
示例7: getReadmore
function getReadmore($text, $length = null)
{
$text = strip_tags($text);
$text = JString::trim($text);
if ($length) {
$text = JString::substr($text, 0, $length + 1);
$last = JString::strrpos($text, ' ');
if ($last) {
$text = JString::substr($text, 0, $last);
$run = true;
while ($run) {
$slength = JString::strlen($text);
if ($slength == 0) {
break;
}
$last = JString::substr($text, $slength - 1, 1);
switch ($last) {
case '.':
case ',':
case '_':
case '-':
$text = JString::substr($text, 0, $slength - 1);
break;
default:
$run = false;
break;
}
}
$text .= ' ...';
}
}
return $text;
}
示例8: testStrrpos
/**
* @group String
* @covers JString::strrpos
* @dataProvider strrposData
*/
public function testStrrpos($haystack, $needle, $offset = 0, $expect)
{
$actual = JString::strrpos($haystack, $needle, $offset);
$this->assertEquals($expect, $actual);
}
示例9: payment
/**
* Get path to payment files.
*
* @param string $alias
* @return array
*/
function payment($alias)
{
return array('button' => ($base = PAYMENTS . DS . JString::substr($alias, 0, JString::strrpos($alias, '_')) . DS) . 'button.php', 'config' => $base . 'config.xml', 'controller' => $base . 'controller.php', 'icon' => $base . 'icon.png');
}
示例10: clipDesc
/**
* Clip text to use as meta description
*
* @param string $text
* @param int $limit
* @return string
*/
function clipDesc($text, $limit)
{
if (JString::strlen($text) > $limit) {
$text = JString::substr($text, 0, $limit);
$pos = JString::strrpos($text, ' ');
if ($pos !== false) {
$text = JString::substr($text, 0, $pos);
}
$text = JString::trim($text);
}
return $text;
}
示例11: mapAvatar
public function mapAvatar($avatarUrl = '', $joomlaUserId, $addWaterMark)
{
$image = '';
if (!empty($avatarUrl)) {
// Make sure user is properly added into the database table first
$user = CFactory::getUser($joomlaUserId);
$fbUser = $this->getUser();
// Load image helper library as it is needed.
CFactory::load('helpers', 'image');
// Store image on a temporary folder.
$tmpPath = JPATH_ROOT . DS . 'images' . DS . 'originalphotos' . DS . 'facebook_connect_' . $fbUser;
/*
print_r($avatarUrl); exit;
$url = parse_url( $avatarUrl );
$host = $url[ 'host' ];
$fp = fsockopen("profile.ak.fbcdn.net", 80, $errno, $errstr, 30);
$path = CString::str_ireplace( $url['scheme'] . '://' . $host , '' , $avatarUrl );
$source = '';
if( $fp )
{
$out = "GET $path HTTP/1.1\r\n";
$out .= "Host: " . $host . "\r\n";
$out .= "Connection: Close\r\n\r\n";
fwrite($fp, $out);
$body = false;
while( !feof( $fp ) )
{
$return = fgets( $fp , 1024 );
if( $body )
{
$source .= $return;
}
if( $return == "\r\n" )
{
$body = true;
}
}
fclose($fp);
}
*/
// Need to extract the non-https version since it will cause
// certificate issue
$avatarUrl = str_replace('https://', 'http://', $avatarUrl);
CFactory::load('helpers', 'remote');
$source = CRemoteHelper::getContent($avatarUrl, true);
list($headers, $source) = explode("\r\n\r\n", $source, 2);
JFile::write($tmpPath, $source);
// @todo: configurable width?
$imageMaxWidth = 160;
// Get a hash for the file name.
$fileName = JUtility::getHash($fbUser . time());
$hashFileName = JString::substr($fileName, 0, 24);
$extension = JString::substr($avatarUrl, JString::strrpos($avatarUrl, '.'));
$type = 'image/jpg';
if ($extension == '.png') {
$type = 'image/png';
}
if ($extension == '.gif') {
$type = 'image/gif';
}
//@todo: configurable path for avatar storage?
$config = CFactory::getConfig();
$storage = JPATH_ROOT . DS . $config->getString('imagefolder') . DS . 'avatar';
$storageImage = $storage . DS . $hashFileName . $extension;
$storageThumbnail = $storage . DS . 'thumb_' . $hashFileName . $extension;
$image = $config->getString('imagefolder') . '/avatar/' . $hashFileName . $extension;
$thumbnail = $config->getString('imagefolder') . '/avatar/' . 'thumb_' . $hashFileName . $extension;
$userModel = CFactory::getModel('user');
// Only resize when the width exceeds the max.
CImageHelper::resizeProportional($tmpPath, $storageImage, $type, $imageMaxWidth);
CImageHelper::createThumb($tmpPath, $storageThumbnail, $type);
if ($addWaterMark) {
// Get the width and height so we can calculate where to place the watermark.
list($watermarkWidth, $watermarkHeight) = getimagesize(FACEBOOK_FAVICON);
list($imageWidth, $imageHeight) = getimagesize($storageImage);
list($thumbWidth, $thumbHeight) = getimagesize($storageThumbnail);
CImageHelper::addWatermark($storageImage, $storageImage, $type, FACEBOOK_FAVICON, $imageWidth - $watermarkWidth, $imageHeight - $watermarkHeight);
CImageHelper::addWatermark($storageThumbnail, $storageThumbnail, $type, FACEBOOK_FAVICON, $thumbWidth - $watermarkWidth, $thumbHeight - $watermarkHeight);
}
// Update the CUser object with the correct avatar.
$user->set('_thumb', $thumbnail);
$user->set('_avatar', $image);
// @rule: once user changes their profile picture, storage method should always be file.
$user->set('_storage', 'file');
$userModel->setImage($joomlaUserId, $image, 'avatar');
$userModel->setImage($joomlaUserId, $thumbnail, 'thumb');
$user->save();
}
}
示例12: getMetaDescriptions
/**
* Get meta description text format. Clean text and crop to 150 characters.
*
* @param string $text
* @return string
*/
public static function getMetaDescriptions($text)
{
$text = JFilterOutput::cleanText($text);
$text = JString::trim($text);
if (JString::strlen($text) <= 150) {
return $text;
}
$text = JString::substr($text, 0, 150);
$lastFullStop = JString::strrpos($text, '.');
if ($lastFullStop !== false) {
$text = JString::substr($text, 0, $lastFullStop + 1);
}
$text = JString::trim($text);
return $text;
}
示例13: getParentPath
/**
* Get path of parent folder from path.
*
* @param string $path
* @return string
*/
public static function getParentPath($path)
{
if (($pos = JString::strrpos($path, DIRECTORY_SEPARATOR)) === false) {
return null;
}
return JString::substr($path, 0, $pos);
}
示例14: prepareAudio
public function prepareAudio($data, $file = null, $_copy = false)
{
$copy = $_copy;
if ($this->tztask) {
$copy = true;
}
if ($data) {
if (isset($data['jform'])) {
$data = $data['jform'];
}
if ($data['audio_soundcloud_id']) {
$fileTypes = array('image/jpeg', 'image/jpg', 'image/bmp', 'image/gif', 'image/png', 'image/ico');
$params = $this->getState('params');
$_data = null;
$_data = $this->_db->quote($data['audio_soundcloud_id']);
$id = $this->getState($this->getName() . '.id');
if (!$id) {
$id = $data['id'];
}
// Create folder to save thumb if this folder isn't created.
$audioPath = $this->imageUrl . DIRECTORY_SEPARATOR . 'cache' . DIRECTORY_SEPARATOR . 'thumbnail' . DIRECTORY_SEPARATOR . $this->audioFolder;
if (!JFolder::exists(JPATH_SITE . DIRECTORY_SEPARATOR . $audioPath)) {
JFolder::create(JPATH_SITE . DIRECTORY_SEPARATOR . $audioPath);
}
if (JFolder::exists(JPATH_SITE . DIRECTORY_SEPARATOR . $audioPath)) {
if (!JFile::exists(JPATH_SITE . DIRECTORY_SEPARATOR . $audioPath . DIRECTORY_SEPARATOR . 'index.html')) {
JFile::write(JPATH_SITE . DIRECTORY_SEPARATOR . $audioPath . DIRECTORY_SEPARATOR . 'index.html', htmlspecialchars_decode('<!DOCTYPE html><title></title>'));
}
}
// Check and set chmod folder again
$chmodFolder = JPath::getPermissions($audioPath);
if ($chmodFolder != 'rwxrwxrwx' || $chmodFolder != 'rwxr-xr-x') {
JPath::setPermissions($audioPath);
}
// Prepare data (Return string to save the database)
//// Delete old thumbnail if delete checkbox input is checked
if ($data['audio_soundcloud_delete_image'] && ($hiddenImage = $data['audio_soundcloud_hidden_image'])) {
$this->deleteThumb(null, $hiddenImage);
// // Delete old original thumbnail
// $org_path = JPATH_SITE.DIRECTORY_SEPARATOR.$org_audioPath.DIRECTORY_SEPARATOR
// .JFile::getName($data['audio_soundcloud_hidden_image']);
// if(JFile::exists($org_path)){
// JFile::delete($org_path);
// }
}
if ($file && !empty($file['name'])) {
// If choose thumbnail from client
$destName = (!$data['alias'] ? uniqid() . 'tz_portfolio_' . time() : $data['alias']) . '-' . $id . '.' . JFile::getExt($file['name']);
$image = $this->uploadImageClient($file, $destName, $audioPath, $fileTypes, $this->_getImageSizes($params), $data['audio_soundcloud_hidden_image']);
} elseif (!empty($data['audio_soundcloud_image_server'])) {
// If choose thumbnail from server
$destName = (!$data['alias'] ? uniqid() . 'tz_portfolio_' . time() : $data['alias']) . '-' . $id . '.' . JFile::getExt($data['audio_soundcloud_image_server']);
$image = $this->uploadImageServer($data['audio_soundcloud_image_server'], $destName, $audioPath, $this->_getImageSizes($params), $data['audio_soundcloud_hidden_image'], $copy);
} else {
// Get thumbnail from soundcloud page
if ($data['audio_soundcloud_delete_image'] && ($hiddenImage = $data['audio_soundcloud_hidden_image'])) {
$data['audio_soundcloud_hidden_image'] = '';
}
if (!isset($data['audio_soundcloud_hidden_image']) || empty($data['audio_soundcloud_hidden_image'])) {
if ($client_id = $params->get('soundcloud_client_id', '4a24c193db998e3b88c34cad41154055')) {
// Register fetch object
$fetch = new Services_Yadis_PlainHTTPFetcher();
$url = 'http://api.soundcloud.com/tracks/' . $data['audio_soundcloud_id'] . '.json?client_id=' . $client_id;
if ($content = $fetch->get($url)) {
$content = json_decode($content->body);
$thumbUrl = null;
if ($content->artwork_url && !empty($content->artwork_url)) {
$thumbUrl = $content->artwork_url;
} else {
$audioUser = $content->user;
if ($audioUser->avatar_url && !empty($audioUser->avatar_url)) {
$thumbUrl = $audioUser->avatar_url;
}
}
if ($thumbUrl) {
if (JString::strrpos($thumbUrl, '-', 0) != false) {
$thumbUrl = JString::substr($thumbUrl, 0, JString::strrpos($thumbUrl, '-', 0) + 1) . 't500x500.' . JFile::getExt($thumbUrl);
}
// Create folder tmp if not exists
if (!JFolder::exists(JPATH_SITE . DIRECTORY_SEPARATOR . 'media' . DIRECTORY_SEPARATOR . $this->tzfolder)) {
JFolder::create(JPATH_SITE . DIRECTORY_SEPARATOR . 'media' . DIRECTORY_SEPARATOR . $this->tzfolder);
}
if (JFolder::exists(JPATH_SITE . DIRECTORY_SEPARATOR . 'media' . DIRECTORY_SEPARATOR . $this->tzfolder)) {
if (!JFile::exists(JPATH_SITE . DIRECTORY_SEPARATOR . 'media' . DIRECTORY_SEPARATOR . $this->tzfolder . 'index.html')) {
JFile::write(JPATH_SITE . DIRECTORY_SEPARATOR . 'media' . DIRECTORY_SEPARATOR . $this->tzfolder . 'index.html', htmlspecialchars_decode('<!DOCTYPE html><title></title>'));
}
}
// Save image from other server to this server (temp file)
$fetch2 = new Services_Yadis_PlainHTTPFetcher();
$audioTempPath = null;
if ($audioTemp = $fetch2->get($thumbUrl)) {
if (in_array($audioTemp->headers['Content-Type'], $fileTypes)) {
$audioType = JFile::getExt($thumbUrl);
if (preg_match('/(.*)(\\|\\/|\\:|\\*|\\?|\\"|\\<|\\>|\\|.*?)/i', $audioType, $match)) {
$audioType = $match[1];
}
$audioTempPath = 'media' . DIRECTORY_SEPARATOR . $this->tzfolder . DIRECTORY_SEPARATOR . uniqid() . time() . '.' . $audioType;
JFile::write(JPATH_SITE . DIRECTORY_SEPARATOR . $audioTempPath, $audioTemp->body);
}
}
//.........这里部分代码省略.........
示例15: truncate
/**
* Alternative to @truncater to truncate contents with HTML codes
*
* @since 1.3
* @access public
* @param string
* @return
*/
public static function truncate($text, $length = 250, $ending = '', $exact = false)
{
// Load site's language file
FD::language()->loadSite();
if (!$ending) {
$ending = JText::_('COM_EASYSOCIAL_ELLIPSES');
}
// If the plain text is shorter than the maximum length, return the whole text
if (JString::strlen(preg_replace('/<.*?>/', '', $text)) <= $length) {
return $text;
}
// splits all html-tags to scanable lines
preg_match_all('/(<.+?>)?([^<>]*)/s', $text, $lines, PREG_SET_ORDER);
$total_length = JString::strlen($ending);
$open_tags = array();
$truncate = '';
foreach ($lines as $line_matchings) {
// if there is any html-tag in this line, handle it and add it (uncounted) to the output
if (!empty($line_matchings[1])) {
// if it's an "empty element" with or without xhtml-conform closing slash
if (preg_match('/^<(\\s*.+?\\/\\s*|\\s*(img|br|input|hr|area|base|basefont|col|frame|isindex|link|meta|param)(\\s.+?)?)>$/is', $line_matchings[1])) {
// do nothing
// if tag is a closing tag
} else {
if (preg_match('/^<\\s*\\/([^\\s]+?)\\s*>$/s', $line_matchings[1], $tag_matchings)) {
// delete tag from $open_tags list
$pos = array_search($tag_matchings[1], $open_tags);
if ($pos !== false) {
unset($open_tags[$pos]);
}
// if tag is an opening tag
} else {
if (preg_match('/^<\\s*([^\\s>!]+).*?>$/s', $line_matchings[1], $tag_matchings)) {
// add tag to the beginning of $open_tags list
array_unshift($open_tags, JString::strtolower($tag_matchings[1]));
}
}
}
// add html-tag to $truncate'd text
$truncate .= $line_matchings[1];
}
// calculate the length of the plain text part of the line; handle entities as one character
$content_length = JString::strlen(preg_replace('/&[0-9a-z]{2,8};|&#[0-9]{1,7};|[0-9a-f]{1,6};/i', ' ', $line_matchings[2]));
if ($total_length + $content_length > $length) {
// the number of characters which are left
$left = $length - $total_length;
$entities_length = 0;
// search for html entities
if (preg_match_all('/&[0-9a-z]{2,8};|&#[0-9]{1,7};|[0-9a-f]{1,6};/i', $line_matchings[2], $entities, PREG_OFFSET_CAPTURE)) {
// calculate the real length of all entities in the legal range
foreach ($entities[0] as $entity) {
if ($entity[1] + 1 - $entities_length <= $left) {
$left--;
$entities_length += JString::strlen($entity[0]);
} else {
// no more characters left
break;
}
}
}
$truncate .= JString::substr($line_matchings[2], 0, $left + $entities_length);
// maximum lenght is reached, so get off the loop
break;
} else {
$truncate .= $line_matchings[2];
$total_length += $content_length;
}
// if the maximum length is reached, get off the loop
if ($total_length >= $length) {
break;
}
}
// if the words shouldn't be cut in the middle...
if (!$exact) {
// ...search the last occurance of a space...
$spacepos = JString::strrpos($truncate, ' ');
if (isset($spacepos)) {
// ...and cut the text in this position
$truncate = JString::substr($truncate, 0, $spacepos);
}
}
// add the defined ending to the text
$truncate .= $ending;
// close all unclosed html-tags
foreach ($open_tags as $tag) {
$truncate .= '</' . $tag . '>';
}
$uid = uniqid();
$theme = FD::themes();
$theme->set('truncated', $truncate);
$theme->set('uid', $uid);
$theme->set('text', $text);
//.........这里部分代码省略.........