本文整理汇总了PHP中JString::strlen方法的典型用法代码示例。如果您正苦于以下问题:PHP JString::strlen方法的具体用法?PHP JString::strlen怎么用?PHP JString::strlen使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JString
的用法示例。
在下文中一共展示了JString::strlen方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: display
public function display($tpl = null)
{
global $option, $mainframe;
$user =& JFactory::getUser();
$model = KFactory::get('admin::com.duuka.model.item');
$item = $model->getItem();
// fail if checked out not by 'me'
if ($model->isCheckedOut($user->get('id'))) {
$msg = JText::sprintf('DESCBEINGEDITTED', JText::_('The weblink'), $item->name);
$mainframe->redirect('index.php?option=' . $option, $msg);
}
/*
* We need to unify the introtext and fulltext fields and have the
* fields separated by the {readmore} tag, so lets do that now.
*/
if (JString::strlen($item->fulltext) > 1) {
$item->text = $item->introtext . "<hr id=\"system-readmore\" />" . $item->fulltext;
} else {
$item->text = $item->introtext;
}
// Mixin a menubar object
$this->mixin(new DuukaMixinMenu($this));
$this->displayMenutitle();
$this->displayToolbar();
$this->displayMenubar();
JRequest::setVar('hidemainmenu', 1);
$this->assignRef('item', $item);
// Display the layout
parent::display($tpl);
}
示例2: addCard
public static function addCard(&$blog, $rawIntroText)
{
$cfg = EasyBlogHelper::getConfig();
// @rule: Check if user really wants to append the opengraph tags on the headers.
if (!$cfg->get('main_twitter_cards')) {
return false;
}
// Get the absolute permalink for this blog item.
$url = EasyBlogRouter::getRoutedURL('index.php?option=com_easyblog&view=entry&id=' . $blog->id, false, true);
// Get the image of the blog post.
$image = self::getImage($blog, $rawIntroText);
// @task: Get Joomla's document object.
$doc = JFactory::getDocument();
// Add card definition.
$doc->addCustomTag('<meta property="twitter:card" content="summary" />');
$doc->addCustomTag('<meta property="twitter:url" content="' . $url . '" />');
$doc->addCustomTag('<meta property="twitter:title" content="' . $blog->title . '" />');
$text = EasyBlogHelper::stripEmbedTags($rawIntroText);
$text = strip_tags($text);
$text = str_ireplace("\r\n", "", $text);
// Remove any " in the content as this would mess up the headers.
$text = str_ireplace('"', '', $text);
$maxLength = 137;
if (!empty($maxLength)) {
$text = JString::strlen($text) > $maxLength ? JString::substr($text, 0, $maxLength) . '...' : $text;
}
$text = EasyBlogStringHelper::escape($text);
$doc->addCustomTag('<meta property="twitter:description" content="' . $text . '" />');
if ($image) {
$doc->addCustomTag('<meta property="twitter:image" content="' . $image . '"/> ');
}
return true;
}
示例3: genericordering
/**
* Description
*
* @param string SQL with ordering As value and 'name field' AS text
* @param integer The length of the truncated headline
* @since 1.5
*/
function genericordering($sql, $chop = '30')
{
$db =& JFactory::getDBO();
$order = array();
$db->setQuery($sql);
if (!($orders = $db->loadObjectList())) {
if ($db->getErrorNum()) {
echo $db->stderr();
return false;
} else {
$order[] = JHTML::_('select.option', 1, JText::_('first'));
return $order;
}
}
$order[] = JHTML::_('select.option', 0, '0 ' . JText::_('first'));
for ($i = 0, $n = count($orders); $i < $n; $i++) {
if (JString::strlen($orders[$i]->text) > $chop) {
$text = JString::substr($orders[$i]->text, 0, $chop) . "...";
} else {
$text = $orders[$i]->text;
}
$order[] = JHTML::_('select.option', $orders[$i]->value, $orders[$i]->value . ' (' . $text . ')');
}
$order[] = JHTML::_('select.option', $orders[$i - 1]->value + 1, $orders[$i - 1]->value + 1 . ' ' . JText::_('last'));
return $order;
}
示例4: __construct
public function __construct(&$subject, $config)
{
parent::__construct($subject, $config);
// Ensure that constructor is called one time
self::$cookie = SID == '';
if (!self::$default_lang) {
$app = JFactory::getApplication();
$router = $app->getRouter();
if ($app->isSite()) {
// setup language data
self::$mode_sef = $router->getMode() == JROUTER_MODE_SEF ? true : false;
self::$sefs = JLanguageHelper::getLanguages('sef');
self::$lang_codes = JLanguageHelper::getLanguages('lang_code');
self::$default_lang = JComponentHelper::getParams('com_languages')->get('site', 'en-GB');
self::$default_sef = self::$lang_codes[self::$default_lang]->sef;
$user = JFactory::getUser();
$levels = $user->getAuthorisedViewLevels();
foreach (self::$sefs as $sef => &$language) {
if (isset($language->access) && $language->access && !in_array($language->access, $levels)) {
unset(self::$sefs[$sef]);
}
}
$app->setLanguageFilter(true);
jimport('joomla.environment.uri');
$uri = JURI::getInstance();
if (self::$mode_sef) {
// Get the route path from the request.
$path = JString::substr($uri->toString(), JString::strlen($uri->base()));
// Apache mod_rewrite is Off
$path = JFactory::getConfig()->get('sef_rewrite') ? $path : JString::substr($path, 10);
// Trim any spaces or slashes from the ends of the path and explode into segments.
$path = JString::trim($path, '/ ');
$parts = explode('/', $path);
// The language segment is always at the beginning of the route path if it exists.
$sef = $uri->getVar('lang');
if (!empty($parts) && empty($sef)) {
$sef = reset($parts);
}
} else {
$sef = $uri->getVar('lang');
}
if (isset(self::$sefs[$sef])) {
$lang_code = self::$sefs[$sef]->lang_code;
// Create a cookie
$conf = JFactory::getConfig();
$cookie_domain = $conf->get('config.cookie_domain', '');
$cookie_path = $conf->get('config.cookie_path', '/');
setcookie(JApplication::getHash('language'), $lang_code, $this->getLangCookieTime(), $cookie_path, $cookie_domain);
$app->input->cookie->set(JApplication::getHash('language'), $lang_code);
// set the request var
$app->input->set('language', $lang_code);
}
}
parent::__construct($subject, $config);
// Detect browser feature
if ($app->isSite()) {
$app->setDetectBrowser($this->params->get('detect_browser', '1') == '1');
}
}
}
示例5: isValid
/**
* Validates the username.
*
* @since 1.0
* @access public
* @param null
* @return JSON A jsong encoded string.
*
* @author Jason Rey <jasonrey@stackideas.com>
*/
public function isValid()
{
// Render the ajax lib.
$ajax = FD::getInstance('Ajax');
// Get the userid
$userid = JRequest::getInt('userid', 0);
// Get the event
$event = JRequest::getString('event');
// Set the current username
$current = '';
if (!empty($userid)) {
$user = FD::user($userid);
$current = $user->username;
}
// Get the provided username that the user has typed.
$username = JRequest::getVar('username', '');
// Username is required, check if username is empty
if (JString::strlen($username) < $this->params->get('min')) {
return $ajax->reject(JText::sprintf('PLG_FIELDS_JOOMLA_USERNAME_MIN_CHARACTERS', $this->params->get('min')));
}
// Test if username is allowed (by pass for adminedit).
if ($event !== 'onAdminEdit' && !SocialFieldsUserJoomlaUsernameHelper::allowed($username, $this->params)) {
return $ajax->reject(JText::_('PLG_FIELDS_JOOMLA_USERNAME_NOT_ALLOWED'));
}
// Test if username exists.
if (SocialFieldsUserJoomlaUsernameHelper::exists($username, $current)) {
return $ajax->reject(JText::_('PLG_FIELDS_JOOMLA_USERNAME_NOT_AVAILABLE'));
}
// Test if the username is valid
if (!SocialFieldsUserJoomlaUsernameHelper::isValid($username, $this->params)) {
return $ajax->reject(JText::_('PLG_FIELDS_JOOMLA_USERNAME_IS_INVALID'));
}
$text = JText::_('PLG_FIELDS_JOOMLA_USERNAME_AVAILABLE');
return $ajax->resolve($text);
}
示例6: _sanitize
/**
* Sanitize a value
*
* @param mixed Value to be sanitized
* @return string
*/
protected function _sanitize($value)
{
$value = parent::_sanitize($value);
$search_ignore = array();
// Limit term to 20 characters
if (JString::strlen($value) > 20) {
$value = JString::substr($value, 0, 19);
}
// Term must contain a minimum of 3 characters
if ($value && JString::strlen($value) < 3) {
$value = '';
}
//Filter out search terms that are too small
$words = explode(' ', JString::strtolower($value));
foreach ($words as $word) {
if (JString::strlen($word) < 3) {
$search_ignore[] = $word;
}
}
if (count($words) > 1) {
$pruned = array_diff($words, $search_ignore);
$value = implode(' ', $pruned);
}
return $value;
}
示例7: genericordering
/**
* Returns an array of options
*
* @param string $sql SQL with ordering As value and 'name field' AS text
* @param integer $chop The length of the truncated headline
*
* @return array An array of objects formatted for JHtml list processing
* @since 11.1
*/
public static function genericordering($sql, $chop = '30')
{
$db = JFactory::getDbo();
$options = array();
$db->setQuery($sql);
$items = $db->loadObjectList();
// Check for a database error.
if ($db->getErrorNum()) {
JError::raiseNotice(500, $db->getErrorMsg());
return false;
}
if (empty($items)) {
$options[] = JHtml::_('select.option', 1, JText::_('JOPTION_ORDER_FIRST'));
return $options;
}
$options[] = JHtml::_('select.option', 0, '0 ' . JText::_('JOPTION_ORDER_FIRST'));
for ($i = 0, $n = count($items); $i < $n; $i++) {
$items[$i]->text = JText::_($items[$i]->text);
if (JString::strlen($items[$i]->text) > $chop) {
$text = JString::substr($items[$i]->text, 0, $chop) . "...";
} else {
$text = $items[$i]->text;
}
$options[] = JHtml::_('select.option', $items[$i]->value, $items[$i]->value . '. ' . $text);
}
$options[] = JHtml::_('select.option', $items[$i - 1]->value + 1, $items[$i - 1]->value + 1 . ' ' . JText::_('JOPTION_ORDER_LAST'));
return $options;
}
示例8: listDirectories
function listDirectories($path, $regex = '.', $recurse = false)
{
$dirs = array();
// Make sure path is valid
jimport('joomla.filesystem.path');
$path = JPath::clean($path);
$root = strlen(JPATH_ROOT) ? JPATH_ROOT : DS;
if (empty($path) || JString::strpos($path, $root) !== 0) {
return $dirs;
}
// Find folders
jimport('joomla.filesystem.folder');
$list = JFolder::folders($path, $regex, $recurse, true);
if (empty($list)) {
return $dirs;
}
// Create list of directories and the names
foreach ($list as $path) {
//$folder = JString::str_ireplace(JPATH_ROOT, '', $path);
$folder = JString::substr($path, JString::strlen($root));
$folder = substr(str_replace(DS, '/', $folder), 1);
$name = @explode('/', $folder);
$name = array_pop($name);
$dirs[] = array('folder' => $folder, 'name' => $name, 'path' => $path, 'path.64' => base64_encode($path));
}
return $dirs;
}
示例9: DefaultViewEventCatRowNew
function DefaultViewEventCatRowNew($view, $row, $args = "")
{
// I choost not to use $row->fgcolor()
$fgcolor = "inherit";
$router = JRouter::getInstance("site");
$vars = $router->getVars();
$vars["catids"] = $row->catid();
if (array_key_exists("Itemid", $vars) && is_null($vars["Itemid"])) {
$vars["Itemid"] = JRequest::getInt("Itemid", 0);
}
$eventlink = "index.php?";
foreach ($vars as $key => $val) {
$eventlink .= $key . "=" . $val . "&";
}
$eventlink = JString::substr($eventlink, 0, JString::strlen($eventlink) - 1);
$eventlink = JRoute::_($eventlink);
?>
<a class="ev_link_cat" href="<?php
echo $eventlink;
?>
" style="color:<?php
echo $fgcolor;
?>
;" title="<?php
echo JEventsHTML::special($row->catname());
?>
"><?php
echo $row->catname();
?>
</a>
<?php
}
示例10: execute
public function execute($item)
{
$model = FD::model('comments');
$users = $model->getParticipants($item->uid, $item->context_type);
$users[] = $item->actor_id;
$users = array_values(array_unique(array_diff($users, array(FD::user()->id))));
$names = FD::string()->namesToNotifications($users);
$plurality = count($users) > 1 ? '_PLURAL' : '_SINGULAR';
$content = '';
if (count($users) == 1 && !empty($item->content)) {
$content = JString::substr(strip_tags($item->content), 0, 30);
if (JString::strlen($item->content) > 30) {
$content .= JText::_('COM_EASYSOCIAL_ELLIPSES');
}
}
$item->content = $content;
list($element, $group, $verb) = explode('.', $item->context_type);
$streamItem = FD::table('streamitem');
$state = $streamItem->load(array('context_type' => $element, 'actor_type' => $group, 'verb' => $verb, 'context_id' => $item->uid));
if (!$state) {
return;
}
$owner = $streamItem->actor_id;
if ($item->target_type === SOCIAL_TYPE_USER && $item->target_id == $owner) {
$item->title = JText::sprintf('APP_USER_ARTICLE_USER_COMMENTED_ON_YOUR_ITEM' . $plurality, $names);
return $item;
}
if ($item->actor_id == $owner && count($users) == 1) {
$item->title = JText::sprintf('APP_USER_ARTICLE_OWNER_COMMENTED_ON_ITEM' . FD::user($owner)->getGenderLang(), $names);
return $item;
}
$item->title = JText::sprintf('APP_USER_ARTICLE_USER_COMMENTED_ON_USER_ITEM' . $plurality, $names, FD::user($owner)->getName());
return $item;
}
示例11: cutText
function cutText($text, $limit_value, $limit_type, $at_end)
{
// solved problem from: https://www.gavick.com/support/forums/47/12309.html?p=57464#p57464
$cck_path = JPATH_BASE . DS . 'components' . DS . 'com_cck';
if (file_exists($cck_path)) {
if (JComponentHelper::isEnabled('com_cck', true)) {
// Force parsing plugin if SEBLOD is used
if ($this->config['parse_plugins'] == FALSE) {
$text = JHtml::_('content.prepare', $text);
}
$text = trim(substr(strip_tags($text, "<br /><br><strong></strong><p></p><i></i><b></b><span></span><ul></ul><li></li><blockquote></blockquote>"), 0));
}
}
if ($limit_type == 'words' && $limit_value > 0) {
$temp = explode(' ', $text);
if (count($temp) > $limit_value) {
for ($i = 0; $i < $limit_value; $i++) {
$cutted[$i] = $temp[$i];
}
$cutted = implode(' ', $cutted);
$text = $cutted . $at_end;
}
} elseif ($limit_type == 'words' && $limit_value == 0) {
return '';
} else {
if (JString::strlen($text) > $limit_value) {
$text = JString::substr($text, 0, $limit_value) . $at_end;
}
}
// replace unnecessary entities at end of the cutted text
$toReplace = array('&&', '&a&', '&am&', '&&', '&q&', '&qu&', '&quo&', '"&', '&ap&', '&apo&', '&apos&');
$text = str_replace($toReplace, '&', $text);
//
return $text;
}
示例12: html
/**
* Outputs the html code for Twitter button
*
* @since 4.0
* @access public
* @param string
* @return
*/
public function html()
{
if (!$this->isEnabled()) {
return;
}
$this->addScript();
// Get the pinterest button style from the configuration
$size = $this->getButtonSize();
$url = EBR::getRoutedURL('index.php?option=com_easyblog&view=entry&id=' . $this->post->id, false, true);
// Combine the introtext and the content
$content = $this->post->intro . $this->post->content;
// Get the media
$media = $this->getMedia();
$contentLength = 350;
$text = $this->post->intro . $this->post->content;
$text = nl2br($text);
$text = strip_tags($text);
$text = trim(preg_replace('/\\s+/', ' ', $text));
$text = JString::strlen($text) > $contentLength ? JString::substr($text, 0, $contentLength) . '...' : $text;
$title = $this->post->title;
// Urlencode all the necessary properties.
$url = urlencode($url);
$text = urlencode($text);
$media = urlencode($media);
$placeholder = $this->getPlaceholderId();
$theme = EB::template();
$theme->set('size', $size);
$theme->set('placeholder', $placeholder);
$theme->set('url', $url);
$theme->set('title', $title);
$theme->set('media', $media);
$theme->set('text', $text);
$output = $theme->output('site/socialbuttons/pinterest');
return $output;
}
示例13: onAfterReply
public function onAfterReply($message)
{
if (JString::strlen($message->message) > $this->params->get('activity_points_limit', 0)) {
CFactory::load('libraries', 'userpoints');
CUserPoints::assignPoint('com_kunena.thread.reply');
}
$content = KunenaHtmlParser::plainBBCode($message->message, $this->params->get('activity_stream_limit', 0));
// Add readmore permalink
$content .= '<br /><a rel="nofollow" href="' . $message->getTopic()->getPermaUrl() . '" class="small profile-newsfeed-item-action">' . JText::_('COM_KUNENA_READMORE') . '</a>';
$act = new stdClass();
$act->cmd = 'wall.write';
$act->actor = $message->userid;
$act->target = 0;
// no target
$act->title = JText::_('{single}{actor}{/single}{multiple}{actors}{/multiple} ' . JText::sprintf('PLG_KUNENA_COMMUNITY_ACTIVITY_REPLY_TITLE', '<a href="' . $message->getTopic()->getUrl() . '">' . $message->subject . '</a>'));
$act->content = $content;
$act->app = 'kunena.post';
$act->cid = $message->thread;
$act->access = $this->getAccess($message->getCategory());
// Comments and like support
$act->comment_id = $message->thread;
$act->comment_type = 'kunena.post';
$act->like_id = $message->thread;
$act->like_type = 'kunena.post';
// Do not add private activities
if ($act->access > 20) {
return;
}
CFactory::load('libraries', 'activities');
CActivityStream::add($act);
}
示例14: getList
public static function getList($params)
{
$db = JFactory::getDBO();
$db->setQuery("SELECT * FROM #__jcomments ORDER BY date DESC", 0, $params->get('count'));
$items = $db->loadObjectList();
if (!is_array($items)) {
$items = array();
}
if (count($items)) {
$config = JCommentsFactory::getConfig();
$bbcode = JCommentsFactory::getBBCode();
$limit_comment_text = (int) $params->get('limit_comment_text', 0);
foreach ($items as &$item) {
$item->link = 'index.php?option=com_jcomments&&view=comment&layout=edit&id=' . $item->id;
$item->author = JComments::getCommentAuthorName($item);
$text = JCommentsText::censor($item->comment);
$text = $bbcode->filter($text, true);
$text = JCommentsText::cleanText($text);
if ($limit_comment_text && JString::strlen($text) > $limit_comment_text) {
$text = self::truncateText($text, $limit_comment_text - 1);
}
$item->comment = $text;
}
}
return $items;
}
示例15: smartSubstr
/**
* Get sub string (by words)
* @param $text
* @param $searchword
* @return mixed|string
*/
public function smartSubstr($text, $searchword)
{
$length = self::MAX_LENGTH;
$textlen = JString::strlen($text);
$lsearchword = JString::strtolower($searchword);
$wordfound = false;
$pos = 0;
$chunk = '';
while ($wordfound === false && $pos < $textlen) {
if (($wordpos = @JString::strpos($text, ' ', $pos + $length)) !== false) {
$chunk_size = $wordpos - $pos;
} else {
$chunk_size = $length;
}
$chunk = JString::substr($text, $pos, $chunk_size);
$wordfound = JString::strpos(JString::strtolower($chunk), $lsearchword);
if ($wordfound === false) {
$pos += $chunk_size + 1;
}
}
if ($wordfound !== false) {
return ($pos > 0 ? '...' : '') . $chunk;
} elseif (($wordpos = @JString::strpos($text, ' ', $length)) !== false) {
return JString::substr($text, 0, $wordpos) . '...';
} else {
return JString::substr($text, 0, $length);
}
}