本文整理汇总了PHP中Hubzero\Utility\String::truncate方法的典型用法代码示例。如果您正苦于以下问题:PHP String::truncate方法的具体用法?PHP String::truncate怎么用?PHP String::truncate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Hubzero\Utility\String
的用法示例。
在下文中一共展示了String::truncate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __invoke
/**
* Truncate some text
*
* @param string $text Text to truncate
* @param integer $length Length to truncate to
* @param array $options Options
* @return string
* @throws \InvalidArgumentException If no text is passed or length isn't a positive integer
*/
public function __invoke($text = null, $length = null, $options = array())
{
if (null === $text) {
throw new \InvalidArgumentException(__METHOD__ . '(); No text passed.');
}
if (!$length || !is_numeric($length)) {
throw new \InvalidArgumentException(__METHOD__ . '(); Length must be an integer');
}
return String::truncate($text, $length, $options);
}
示例2: check
/**
* Validate data
*
* @return boolean True if data is valid
*/
public function check()
{
$this->message = trim($this->message);
if ($this->message == '') {
$this->setError(Lang::txt('SUPPORT_ERROR_BLANK_FIELD'));
return false;
}
$this->title = trim($this->title);
if (!$this->title) {
$this->title = String::truncate($this->message, 250);
}
return true;
}
示例3: __construct
/**
* Constructor
*
* @param integer $scope_id Scope ID (group, course, etc.)
* @return void
*/
public function __construct($scope_id = 0)
{
$this->set('scope_id', $scope_id);
include_once PATH_CORE . DS . 'components' . DS . 'com_courses' . DS . 'models' . DS . 'courses.php';
$offering = \Components\Courses\Models\Offering::getInstance($this->get('scope_id'));
$course = \Components\Courses\Models\Course::getInstance($offering->get('course_id'));
$this->_segments['gid'] = $course->get('alias');
$this->_segments['offering'] = $offering->alias();
$this->_segments['active'] = 'discussions';
if (Request::getVar('active') == 'outline') {
$this->_segments['active'] = 'outline';
}
$this->_name = String::truncate($course->get('alias'), 50) . ': ' . String::truncate($offering->get('alias'), 50);
}
示例4: _process
/**
* Process data
*
* @return void
*/
protected function _process()
{
// New project?
$new = $this->model->exists() ? false : true;
// Are we in setup?
$setup = $new || $this->model->inSetup() ? true : false;
// Incoming
$private = Request::getInt('private', 1);
// Save section
switch ($this->section) {
case 'describe':
case 'info':
// Incoming
$name = trim(Request::getVar('name', '', 'post'));
$title = trim(Request::getVar('title', '', 'post'));
$name = preg_replace('/ /', '', $name);
$name = strtolower($name);
// Clean up title from any scripting
$title = preg_replace('/\\s+/', ' ', $title);
$title = $this->_txtClean($title);
// Check incoming data
if ($setup && $new && !$this->model->check($name, $this->model->get('id'))) {
$this->setError(Lang::txt('COM_PROJECTS_ERROR_NAME_INVALID_OR_EMPTY'));
return false;
} elseif (!$title) {
$this->setError(Lang::txt('COM_PROJECTS_ERROR_TITLE_SHORT_OR_EMPTY'));
return false;
}
if ($this->model->exists()) {
$this->model->set('modified', Date::toSql());
$this->model->set('modified_by', User::get('id'));
} else {
$this->model->set('alias', $name);
$this->model->set('created', Date::toSql());
$this->model->set('created_by_user', User::get('id'));
$this->model->set('owned_by_group', $this->_gid);
$this->model->set('owned_by_user', User::get('id'));
$this->model->set('private', $this->config->get('privacy', 1));
}
$this->model->set('title', \Hubzero\Utility\String::truncate($title, 250));
$this->model->set('about', trim(Request::getVar('about', '', 'post', 'none', 2)));
$this->model->set('type', Request::getInt('type', 1, 'post'));
// save advanced permissions
if (isset($_POST['private'])) {
$this->model->set('private', $private);
}
if ($setup && !$this->model->exists()) {
// Copy params from default project type
$objT = $this->model->table('Type');
$this->model->set('params', $objT->getParams($this->model->get('type')));
}
// Save changes
if (!$this->model->store()) {
$this->setError($this->model->getError());
return false;
}
// Save owners for new projects
if ($new) {
$this->_identifier = $this->model->get('alias');
// Group owners
$objO = $this->model->table('Owner');
if ($this->_gid) {
if (!$objO->saveOwners($this->model->get('id'), User::get('id'), 0, $this->_gid, 0, 1, 1, '', $split_group_roles = 0)) {
$this->setError(Lang::txt('COM_PROJECTS_ERROR_SAVING_AUTHORS') . ': ' . $objO->getError());
return false;
}
// Make sure project creator is manager
$objO->reassignRole($this->model->get('id'), $users = array(User::get('id')), 0, 1);
} elseif (!$objO->saveOwners($this->model->get('id'), User::get('id'), User::get('id'), $this->_gid, 1, 1, 1)) {
$this->setError(Lang::txt('COM_PROJECTS_ERROR_SAVING_AUTHORS') . ': ' . $objO->getError());
return false;
}
}
break;
case 'team':
if ($new) {
return false;
}
// Save team
$content = Event::trigger('projects.onProject', array($this->model, 'save', array('team')));
if (isset($content[0]) && $this->next == $this->section) {
if (isset($content[0]['msg']) && !empty($content[0]['msg'])) {
$this->_setNotification($content[0]['msg']['message'], $content[0]['msg']['type']);
}
}
break;
case 'settings':
if ($new) {
return false;
}
// Save privacy
if (isset($_POST['private'])) {
$this->model->set('private', $private);
// Save changes
if (!$this->model->store()) {
//.........这里部分代码省略.........
示例5: out
/**
* Static method for formatting results
*
* @param object $row Database row
* @return string HTML
*/
public static function out($row)
{
$row->href = Route::url($row->href);
$month = Date::of($row->publish_up)->toLocal('M');
$day = Date::of($row->publish_up)->toLocal('d');
$year = Date::of($row->publish_up)->toLocal('Y');
// Start building the HTML
$html = "\t" . '<li class="event">' . "\n";
$html .= "\t\t" . '<p class="event-date"><span class="month">' . $month . '</span> <span class="day">' . $day . '</span> <span class="year">' . $year . '</span></p>' . "\n";
$html .= "\t\t" . '<p class="title"><a href="' . $row->href . '">' . stripslashes($row->title) . '</a></p>' . "\n";
if ($row->ftext) {
$row->ftext = str_replace('[[BR]]', '', $row->ftext);
// Remove tags to prevent tables from being displayed within a table.
$row->ftext = strip_tags($row->ftext);
$html .= "\t\t" . \Hubzero\Utility\String::truncate(\Hubzero\Utility\Sanitize::stripAll(stripslashes($row->ftext)), 200) . "\n";
}
$html .= "\t\t" . '<p class="href">' . Request::base() . trim($row->href, '/') . '</p>' . "\n";
$html .= "\t" . '</li>' . "\n";
// Return output
return $html;
}
示例6:
echo $this->pub->id;
?>
" />
<input type="hidden" name="vid" value="<?php
echo $this->pub->version_id;
?>
" />
<input type="hidden" name="task" id="task" value="save" />
</fieldset>
<div class="curation-wrap">
<div class="pubtitle">
<h3><span class="restype indlist"><?php
echo $typetitle;
?>
</span> <?php
echo \Hubzero\Utility\String::truncate($this->pub->title, 65);
?>
| <?php
echo Lang::txt('COM_PUBLICATIONS_CURATION_VERSION') . ' ' . $this->pub->version_label;
?>
</h3>
</div>
<p class="instruct">
<span class="pubimage"><img src="<?php
echo Route::url('index.php?option=com_publications&id=' . $this->pub->id . '&v=' . $this->pub->version_id) . '/Image:thumb';
?>
" alt="" /></span>
<strong class="block"><?php
echo $this->pub->reviewed ? Lang::txt('COM_PUBLICATIONS_CURATION_RESUBMITTED') : Lang::txt('COM_PUBLICATIONS_CURATION_SUBMITTED');
echo ' ' . Date::of($this->pub->submitted)->toLocal('M d, Y') . ' ' . Lang::txt('COM_PUBLICATIONS_CURATION_BY') . ' ' . $this->pub->modifier('name');
?>
示例7: onAfterStatusChange
/**
* On after approve/kickback
*
* @return void
*/
public function onAfterStatusChange()
{
if ($this->getError()) {
return;
}
$pub = $this->_pub;
$status = $this->_pub->version->state;
$activity = $status == 1 ? Lang::txt('COM_PUBLICATIONS_CURATION_ACTIVITY_PUBLISHED') : Lang::txt('COM_PUBLICATIONS_CURATION_ACTIVITY_KICKBACK');
$pubtitle = \Hubzero\Utility\String::truncate($pub->title, 100);
// Log activity in curation history
$pub->_curationModel->saveHistory(User::get('id'), $pub->state, $status, 1);
// Add activity
$activity .= ' ' . strtolower(Lang::txt('version')) . ' ' . $pub->version_label . ' ' . Lang::txt('COM_PUBLICATIONS_OF') . ' ' . strtolower(Lang::txt('publication')) . ' "' . $pubtitle . '" ';
// Record activity
$aid = $pub->project()->recordActivity($activity, $pub->id, $pubtitle, $pub->link('version'), 'publication', 0, $admin = 1);
// Start message
$sef = 'publications' . DS . $pub->id . DS . $pub->version_number;
$link = rtrim(Request::base(), DS) . DS . trim($pub->link('version'), DS);
$manage = rtrim(Request::base(), DS) . DS . trim($pub->link('editversion'), DS);
$message = $status == 1 ? Lang::txt('COM_PUBLICATIONS_CURATION_EMAIL_CURATOR_APPROVED') : Lang::txt('COM_PUBLICATIONS_CURATION_EMAIL_CURATOR_KICKED_BACK');
if ($status != 1) {
$message .= "\n" . "\n";
$message .= Lang::txt('COM_PUBLICATIONS_CURATION_TAKE_ACTION') . ' ' . $manage;
} else {
$message .= ' ' . $link;
}
$pubtitle = \Hubzero\Utility\String::truncate($pub->title, 100);
$subject = ucfirst(Lang::txt('COM_PUBLICATIONS_CURATION_VERSION')) . ' ' . $pub->version_label . ' ' . Lang::txt('COM_PUBLICATIONS_OF') . ' ' . strtolower(Lang::txt('COM_PUBLICATIONS_PUBLICATION')) . ' "' . $pubtitle . '" ';
$subject .= $status == 1 ? Lang::txt('COM_PUBLICATIONS_MSG_ADMIN_PUBLISHED') : Lang::txt('COM_PUBLICATIONS_MSG_ADMIN_KICKED_BACK');
// Get authors
$authors = $pub->table('Author')->getAuthors($pub->version_id, 1, 1, 1);
// No authors – send to publication creator
if (count($authors) == 0) {
$authors = array($pub->created_by);
}
// New version released?
if ($status == 1 && $pub->get('version_number') > 1) {
// Notify subsrcibers
Event::trigger('publications.onWatch', array($pub));
}
// Make sure there are no duplicates
$authors = array_unique($authors);
// Notify authors
Helpers\Html::notify($pub, $authors, $subject, $message, true);
return;
}
示例8: content
/**
* Get the content of the entry
*
* @param string $as Format to return state in [text, number]
* @param integer $shorten Number of characters to shorten text to
* @return string
*/
public function content($as = 'parsed', $shorten = 0)
{
$as = strtolower($as);
$options = array();
switch ($as) {
case 'parsed':
$content = $this->get('comment.parsed', null);
if ($content === null) {
$config = array('option' => $this->get('option', 'com_projects'), 'scope' => $this->get('scope'), 'pagename' => $this->get('alias'), 'pageid' => 0, 'filepath' => $this->get('path'), 'domain' => '');
$content = str_replace(array('\\"', "\\'"), array('"', "'"), (string) $this->get('comment', ''));
$this->importPlugin('content')->trigger('onContentPrepare', array($this->_context, &$this, &$config));
$this->set('comment.parsed', (string) $this->get('comment', ''));
$this->set('comment', $content);
return $this->content($as, $shorten);
}
$options['html'] = true;
break;
case 'clean':
$content = strip_tags($this->content('parsed'));
break;
case 'raw':
default:
$content = str_replace(array('\\"', "\\'"), array('"', "'"), $this->get('comment'));
$content = preg_replace('/^(<!-- \\{FORMAT:.*\\} -->)/i', '', $content);
break;
}
if ($shorten) {
$content = \Hubzero\Utility\String::truncate($content, $shorten, $options);
}
return $content;
}
示例9: strip_tags
$when = Date::of($row->proposed)->relative();
$title = strip_tags($row->about) ? $this->escape(stripslashes($row->subject)) . ' :: ' . \Hubzero\Utility\String::truncate($this->escape(strip_tags($row->about)), 160) : NULL;
?>
<li class="wishlist">
<a href="<?php
echo Route::url('index.php?option=com_wishlist&task=wish&id=' . $row->wishlist . '&wishid=' . $row->id);
?>
" class="tooltips" title="<?php
echo $title;
?>
">
#<?php
echo $row->id;
?>
: <?php
echo \Hubzero\Utility\String::truncate(stripslashes($row->subject), 35);
?>
</a>
<span>
<span class="<?php
echo $row->status == 3 ? 'rejected' : '';
if ($row->status == 0) {
echo $row->accepted == 1 ? 'accepted' : 'pending';
}
?>
">
<?php
echo $row->status == 3 ? Lang::txt('MOD_MYWISHES_REJECTED') : '';
if ($row->status == 0) {
echo $row->accepted == 1 ? Lang::txt('MOD_MYWISHES_ACCEPTED') : Lang::txt('MOD_MYWISHES_PENDING');
}
示例10:
</dd>
<?php
}
if ($params->get('show_author') or $params->get('show_category') or $params->get('show_create_date') or $params->get('show_modify_date') or $params->get('show_publish_date') or $params->get('show_hits')) {
?>
</dl>
<?php
}
?>
<?php
if ($params->get('show_intro')) {
?>
<div class="intro">
<?php
echo \Hubzero\Utility\String::truncate($item->introtext, $params->get('introtext_limit'));
?>
</div>
<?php
}
?>
</li>
<?php
}
?>
</ul>
<div class="pagination">
<p class="counter">
<?php
echo $this->pagination->getPagesCounter();
示例11:
echo $this->escape(stripslashes($this->title));
?>
" />
</a>
</p>
<?php
}
?>
<p>
<a href="<?php
echo Route::url('index.php?option=com_members&id=' . $this->id);
?>
">
<?php
echo $this->escape(stripslashes($this->title));
?>
</a>:
<?php
if ($this->txt) {
?>
<?php
echo \Hubzero\Utility\String::truncate($this->escape(strip_tags($this->txt)), $this->txt_length);
?>
<?php
}
?>
</p>
</div>
<?php
}
}
示例12: feedTask
/**
* Generate an RSS feed of entries
*
* @return void
*/
public function feedTask()
{
if (!$this->config->get('feeds_enabled')) {
App::redirect(Route::url('index.php?option=' . $this->_option));
return;
}
// Set the mime encoding for the document
Document::setType('feed');
// Start a new feed object
$doc = Document::instance();
$doc->link = Route::url('index.php?option=' . $this->_option);
// Incoming
$filters = array('year' => Request::getInt('year', 0), 'month' => Request::getInt('month', 0), 'scope' => $this->config->get('show_from', 'site'), 'scope_id' => 0, 'search' => Request::getVar('search', ''), 'authorized' => false, 'state' => 1, 'access' => User::getAuthorisedViewLevels());
if ($filters['year'] > date("Y")) {
$filters['year'] = 0;
}
if ($filters['month'] > 12) {
$filters['month'] = 0;
}
if ($filters['scope'] == 'both') {
$filters['scope'] = '';
}
if (!User::isGuest()) {
if ($this->config->get('access-manage-component')) {
//$filters['state'] = null;
$filters['authorized'] = true;
array_push($filters['access'], 5);
}
}
// Build some basic RSS document information
$doc->title = Config::get('sitename') . ' - ' . Lang::txt(strtoupper($this->_option));
$doc->title .= $filters['year'] ? ': ' . $filters['year'] : '';
$doc->title .= $filters['month'] ? ': ' . sprintf("%02d", $filters['month']) : '';
$doc->description = Lang::txt('COM_BLOG_RSS_DESCRIPTION', Config::get('sitename'));
$doc->copyright = Lang::txt('COM_BLOG_RSS_COPYRIGHT', date("Y"), Config::get('sitename'));
$doc->category = Lang::txt('COM_BLOG_RSS_CATEGORY');
// Get the records
$rows = $this->model->entries($filters)->ordered()->paginated()->rows();
// Start outputing results if any found
if ($rows->count() > 0) {
foreach ($rows as $row) {
$item = new \Hubzero\Document\Type\Feed\Item();
// Strip html from feed item description text
$item->description = $row->content();
$item->description = html_entity_decode(Sanitize::stripAll($item->description));
if ($this->config->get('feed_entries') == 'partial') {
$item->description = String::truncate($item->description, 300);
}
$item->description = '<![CDATA[' . $item->description . ']]>';
// Load individual item creator class
$item->title = html_entity_decode(strip_tags($row->get('title')));
$item->link = Route::url($row->link());
$item->date = date('r', strtotime($row->published()));
$item->category = '';
$item->author = $row->creator()->get('email') . ' (' . $row->creator()->get('name') . ')';
// Loads item info into rss array
$doc->addItem($item);
}
}
}
示例13: render
/**
* Generate macro output
*
* @return string
*/
public function render()
{
// check if we can render
if (!parent::canRender()) {
return \Lang::txt('[This macro is designed for Groups only]');
}
// get args
$args = $this->getArgs();
// get details
$type = $this->_getType($args, 'all');
$limit = $this->_getLimit($args, 5);
$class = $this->_getClass($args);
//get resources
$groupResources = $this->_getResources($type, $limit);
$html = '<div class="resources ' . $class . '">';
foreach ($groupResources as $resource) {
$area = strtolower(preg_replace("/[^a-zA-Z0-9]/", '', $resource->area));
$resourceLink = \Route::url('index.php?option=com_resources&id=' . $resource->id);
$resourceTypeLink = \Route::url('index.php?option=com_groups&cn=' . $this->group->get('cn') . '&active=resources&area=' . $area);
$html .= '<a href="' . $resourceLink . '"><strong>' . $resource->title . '</strong></a>';
$html .= '<p class="category"> in: <a href="' . $resourceTypeLink . '">' . $resource->area . '</a></p>';
$html .= '<p>' . \Hubzero\Utility\String::truncate($resource->itext) . '</p>';
}
$html .= '</div>';
return $html;
}
示例14: ucfirst
// Does this category have a unique output display?
$func = 'plgWhatsnew' . ucfirst($row->section) . 'Out';
// Check if a method exist (using JPlugin style)
$obj = 'plgWhatsnew' . ucfirst($this->cats[$k]['category']);
if (function_exists($func)) {
$html .= $func($row, $this->period);
} elseif (method_exists($obj, 'out')) {
$html .= call_user_func(array($obj, 'out'), $row, $this->period);
} else {
if (strstr($row->href, 'index.php')) {
$row->href = Route::url($row->href);
}
$html .= "\t" . '<li>' . "\n";
$html .= "\t\t" . '<p class="title"><a href="' . $row->href . '">' . stripslashes($row->title) . '</a></p>' . "\n";
if ($row->text) {
$html .= "\t\t" . '<p>' . \Hubzero\Utility\String::truncate(strip_tags(\Hubzero\Utility\Sanitize::stripAll(stripslashes($row->text))), 200) . '</p>' . "\n";
}
$html .= "\t\t" . '<p class="href">' . rtrim(Request::getSchemeAndHttpHost(), '/') . '/' . ltrim($row->href, '/') . '</p>' . "\n";
$html .= "\t" . '</li>' . "\n";
}
}
$html .= '</ol>' . "\n";
// Initiate paging if we we're displaying an active category
if ($dopaging) {
$pageNav = $this->pagination($this->total, $this->start, $this->limit);
$pageNav->setAdditionalUrlParam('category', urlencode(strToLower($this->active)));
$pageNav->setAdditionalUrlParam('period', $this->period);
$html .= $pageNav->render();
$html .= '<div class="clearfix"></div>';
} else {
$html .= '<p class="moreresults">' . Lang::txt('COM_WHATSNEW_TOP_SHOWN', $amt);
示例15: _feed
/**
* Display an RSS feed of latest entries
*
* @return string
*/
private function _feed()
{
if (!$this->params->get('feeds_enabled', 1)) {
return $this->_browse();
}
include_once PATH_CORE . DS . 'libraries' . DS . 'joomla' . DS . 'document' . DS . 'feed' . DS . 'feed.php';
// Filters for returning results
$filters = array('limit' => Request::getInt('limit', Config::get('list_limit')), 'start' => Request::getInt('limitstart', 0), 'year' => Request::getInt('year', 0), 'month' => Request::getInt('month', 0), 'scope' => 'group', 'scope_id' => $this->group->get('gidNumber'), 'search' => Request::getVar('search', ''), 'created_by' => Request::getInt('author', 0), 'state' => 'public');
$path = Request::path();
if (strstr($path, '/')) {
$bits = $this->_parseUrl();
$filters['year'] = isset($bits[0]) && is_numeric($bits[0]) ? $bits[0] : $filters['year'];
$filters['month'] = isset($bits[1]) && is_numeric($bits[1]) ? $bits[1] : $filters['month'];
}
if ($filters['year'] > date("Y")) {
$filters['year'] = 0;
}
if ($filters['month'] > 12) {
$filters['month'] = 0;
}
// Set the mime encoding for the document
Document::setType('feed');
// Start a new feed object
$doc = Document::instance();
$doc->link = Route::url('index.php?option=' . $this->option . '&cn=' . $this->group->get('cn') . '&active=' . $this->_name);
// Build some basic RSS document information
$doc->title = Config::get('sitename') . ': ' . Lang::txt('Groups') . ': ' . stripslashes($this->group->get('description')) . ': ' . Lang::txt('Blog');
$doc->description = Lang::txt('PLG_GROUPS_BLOG_RSS_DESCRIPTION', $this->group->get('cn'), Config::get('sitename'));
$doc->copyright = Lang::txt('PLG_GROUPS_BLOG_RSS_COPYRIGHT', date("Y"), Config::get('sitename'));
$doc->category = Lang::txt('PLG_GROUPS_BLOG_RSS_CATEGORY');
$rows = $this->model->entries($filters)->ordered()->paginated()->rows();
// Start outputing results if any found
if ($rows->count() > 0) {
foreach ($rows as $row) {
$item = new \Hubzero\Document\Type\Feed\Item();
// Strip html from feed item description text
$item->description = $row->content;
$item->description = \Hubzero\Utility\Sanitize::stripAll(strip_tags(html_entity_decode($item->description)));
if ($this->params->get('feed_entries') == 'partial') {
$item->description = \Hubzero\Utility\String::truncate($item->description, 300);
}
$item->description = '<![CDATA[' . $item->description . ']]>';
// Load individual item creator class
$item->title = html_entity_decode(strip_tags($row->get('title')));
$item->link = Route::url($row->link());
$item->date = date('r', strtotime($row->published()));
$item->category = '';
$item->author = $row->creator()->get('name');
// Loads item info into rss array
$doc->addItem($item);
}
}
// Output the feed
echo $doc->render();
exit;
}