本文整理汇总了PHP中SliceString函数的典型用法代码示例。如果您正苦于以下问题:PHP SliceString函数的具体用法?PHP SliceString怎么用?PHP SliceString使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了SliceString函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: GetPropertiesFromDataSet
function GetPropertiesFromDataSet($DataSet, &$Context)
{
$this->Title = FormatHtmlStringInline(ForceString($DataSet["Name"], ""));
$this->Link = PrependString("http://", AppendFolder(agDOMAIN, "comments.php?DiscussionID=" . ForceInt($DataSet["DiscussionID"], 0)));
$this->Id = $this->Link;
$this->Published = FixDate(@$DataSet["DateCreated"]);
$this->Updated = FixDate(@$DataSet["DateLastActive"]);
$this->AuthorName = FormatHtmlStringInline(ForceString($DataSet["AuthUsername"], ""));
$this->AuthorUrl = PrependString("http://", AppendFolder(agDOMAIN, "account.php?u=" . ForceInt($DataSet["AuthUserID"], 0)));
$this->Content = $this->RemoveHtml(ForceString(@$DataSet["Body"], ""));
$this->Summary = SliceString($this->Content, 200);
$this->Summary = str_replace("\r\n", " ", $this->Content);
$this->Content = str_replace("\r\n", "<br />", $this->Content);
if (agUSE_CATEGORIES) {
$this->Category = FormatStringForDisplay(ForceString($DataSet["Category"], ""), true);
$this->CategoryLink = "http://" . AppendFolder(agDOMAIN, "?CategoryID=" . ForceInt($DataSet["CategoryID"], 0));
}
}
示例2: EvalConfigurationCode
/**
* Eval code.
* Returns array() on success.
* Returns string on failure.
*
* @param mixed $Code
* @return mixed $Result.
*/
private static function EvalConfigurationCode($Code)
{
$Lines = explode("\n", $Code);
$NewLines = array();
foreach ($Lines as $Line) {
$Line = trim($Line);
if ($Line == '') {
continue;
}
if (substr($Line, 0, 14) != '$Configuration') {
return 'Unexpected: ' . SliceString($Line, 50);
}
$Tokens = token_get_all('<?php ' . $Line);
$Key = array_search(';', $Tokens, True);
if ($Key === False) {
continue;
}
$Tokens = array_slice($Tokens, 0, $Key + 1);
$JoinStrings = False;
$Line = '';
foreach ($Tokens as $Token) {
if ($JoinStrings == False) {
if (is_array($Token) && $Token[0] == 309 && $Token[1] == '$Configuration') {
$JoinStrings = True;
}
}
if (!$JoinStrings) {
continue;
}
if (is_array($Token)) {
$Token = $Token[1];
}
$Line .= $Token;
}
$NewLines[] = $Line;
}
if (count($NewLines) == 0) {
return 'Nothing to write.';
}
return $NewLines;
//if (!$ErrorString) $ErrorString = 'Something funky happened.';
//return $ErrorString;
}
示例3: HighlightTrimmedString
function HighlightTrimmedString($Haystack, $Needles, $TrimLength = '')
{
$Highlight = '<span class="Highlight">\\1</span>';
$Pattern = '#(?!<.*?)(%s)(?![^<>]*?>)#i';
$TrimLength = ForceInt($TrimLength, 0);
if ($TrimLength > 0) {
$Haystack = SliceString($Haystack, $TrimLength);
}
$WordsToHighlight = count($Needles);
if ($WordsToHighlight > 0) {
$i = 0;
for ($i = 0; $i < $WordsToHighlight; $i++) {
if (strlen($Needles[$i]) > 2) {
$CurrentWord = preg_quote($Needles[$i]);
$Regex = sprintf($Pattern, $CurrentWord);
$Haystack = preg_replace($Regex, $Highlight, $Haystack);
}
}
}
return $Haystack;
}
示例4: elseif
break;
}
} elseif (!$LastPhoto) {
$LastPhoto = UserPhoto($User);
}
}
$CssClass = 'Item';
$CssClass .= $Alt ? ' Alt' : '';
$CssClass .= $Conversation->CountNewMessages > 0 ? ' New' : '';
$CssClass .= $LastPhoto != '' ? ' HasPhoto' : '';
$CssClass .= ' ' . ($Conversation->CountNewMessages <= 0 ? 'Read' : 'Unread');
$JumpToItem = $Conversation->CountMessages - $Conversation->CountNewMessages;
if ($Conversation->LastFormat == 'Text') {
$Message = SliceString(Gdn_Format::To($Conversation->LastBody, $Conversation->LastFormat), 100);
} else {
$Message = SliceString(Gdn_Format::Text(Gdn_Format::To($Conversation->LastBody, $Conversation->LastFormat), FALSE), 100);
}
if (StringIsNullOrEmpty(trim($Message))) {
$Message = T('Blank Message');
}
$this->EventArguments['Conversation'] = $Conversation;
?>
<li class="<?php
echo $CssClass;
?>
">
<?php
$Names = '';
foreach ($Conversation->Participants as $User) {
$Names = ConcatSep(', ', $Names, FormatUsername($User, 'You'));
}
示例5: searchExcerpt
function searchExcerpt($PlainText, $SearchTerms, $Length = 200, $Mark = true)
{
if (empty($SearchTerms)) {
return substrWord($PlainText, 0, $Length);
}
if (is_string($SearchTerms)) {
$SearchTerms = preg_split('`[\\s|-]+`i', $SearchTerms);
}
// Split the string into lines.
$Lines = explode("\n", $PlainText);
// Find the first line that includes a search term.
foreach ($Lines as $i => &$Line) {
$Line = trim($Line);
if (!$Line) {
continue;
}
foreach ($SearchTerms as $Term) {
if (!$Term) {
continue;
}
if (($Pos = mb_stripos($Line, $Term)) !== false) {
$Line = substrWord($Line, $Term, $Length);
if ($Mark) {
return MarkString($SearchTerms, $Line);
} else {
return $Line;
}
}
}
}
// No line was found so return the first non-blank line.
foreach ($Lines as $Line) {
if ($Line) {
return SliceString($Line, $Length);
}
}
return '';
}
示例6: writeTableRow
function writeTableRow($Row, $Depth = 1)
{
$Children = $Row['Children'];
$WriteChildren = FALSE;
if (!empty($Children)) {
if ($Depth + 1 >= c('Vanilla.Categories.MaxDisplayDepth')) {
$WriteChildren = 'list';
} else {
$WriteChildren = 'rows';
}
}
$H = 'h' . ($Depth + 1);
?>
<tr class="<?php
echo CssClass($Row);
?>
">
<td class="CategoryName">
<div class="Wrap">
<?php
echo GetOptions($Row);
echo CategoryPhoto($Row);
echo "<{$H}>";
echo anchor(htmlspecialchars($Row['Name']), $Row['Url']);
Gdn::controller()->EventArguments['Category'] = $Row;
Gdn::controller()->fireEvent('AfterCategoryTitle');
echo "</{$H}>";
?>
<div class="CategoryDescription">
<?php
echo $Row['Description'];
?>
</div>
<?php
if ($WriteChildren === 'list') {
?>
<div class="ChildCategories">
<?php
echo wrap(t('Child Categories') . ': ', 'b');
echo CategoryString($Children, $Depth + 1);
?>
</div>
<?php
}
?>
</div>
</td>
<td class="BigCount CountDiscussions">
<div class="Wrap">
<?php
// echo "({$Row['CountDiscussions']})";
echo BigPlural($Row['CountAllDiscussions'], '%s discussion');
?>
</div>
</td>
<td class="BigCount CountComments">
<div class="Wrap">
<?php
// echo "({$Row['CountComments']})";
echo BigPlural($Row['CountAllComments'], '%s comment');
?>
</div>
</td>
<td class="BlockColumn LatestPost">
<div class="Block Wrap">
<?php
if ($Row['LastTitle']) {
?>
<?php
echo userPhoto($Row, array('Size' => 'Small', 'Px' => 'Last'));
echo anchor(SliceString(Gdn_Format::text($Row['LastTitle']), 100), $Row['LastUrl'], 'BlockTitle LatestPostTitle', array('title' => html_entity_decode($Row['LastTitle'])));
?>
<div class="Meta">
<?php
echo userAnchor($Row, 'UserLink MItem', 'Last');
?>
<span class="Bullet">•</span>
<?php
echo anchor(Gdn_Format::date($Row['LastDateInserted'], 'html'), $Row['LastUrl'], 'CommentDate MItem');
if (isset($Row['LastCategoryID'])) {
$LastCategory = CategoryModel::categories($Row['LastCategoryID']);
echo ' <span>', sprintf('in %s', anchor($LastCategory['Name'], CategoryUrl($LastCategory, '', '//'))), '</span>';
}
?>
</div>
<?php
}
?>
</div>
</td>
</tr>
<?php
if ($WriteChildren === 'rows') {
foreach ($Children as $ChildRow) {
WriteTableRow($ChildRow, $Depth + 1);
}
}
}
示例7: SliceParagraph
/**
* Slices a string at a paragraph.
* This function will attempt to slice a string at paragraph that is no longer than the specified maximum length.
* If it can't slice the string at a paragraph it will attempt to slice on a sentence.
*
* Note that you should not expect this function to return a string that is always shorter than max-length.
* The purpose of this function is to provide a string that is reaonably easy to consume by a human.
*
* @param string $String The string to slice.
* @param int $MaxLength The maximum length of the string.
* @param string $Suffix The suffix if the string must be sliced mid-sentence.
* @return string
*/
function SliceParagraph($String, $MaxLength = 500, $Suffix = '…')
{
if ($MaxLength >= strlen($String)) {
return $String;
}
// $String = preg_replace('`\s+\n`', "\n", $String);
// See if there is a paragraph.
$Pos = strrpos(SliceString($String, $MaxLength, ''), "\n\n");
if ($Pos === FALSE) {
// There was no paragraph so try and split on sentences.
$Sentences = preg_split('`([.!?:]\\s+)`', $String, NULL, PREG_SPLIT_DELIM_CAPTURE);
$Result = '';
if (count($Sentences) > 1) {
$Result = $Sentences[0] . $Sentences[1];
for ($i = 2; $i < count($Sentences); $i++) {
$Sentence = $Sentences[$i];
if (strlen($Result) + strlen($Sentence) <= $MaxLength || preg_match('`[.!?:]\\s+`', $Sentence)) {
$Result .= $Sentence;
} else {
break;
}
}
}
if ($Result) {
return rtrim($Result);
}
// There was no sentence. Slice off the last word and call it a day.
$Pos = strrpos(SliceString($String, $MaxLength, ''), ' ');
if ($Pos === FALSE) {
return $String . $Suffix;
} else {
return SliceString($String, $Pos + 1, $Suffix);
}
} else {
return substr($String, 0, $Pos + 1);
}
}
示例8: ModerationController_MergeDiscussions_Create
/**
* Add a method to the ModerationController to handle merging discussions.
* @param Gdn_Controller $Sender
*/
public function ModerationController_MergeDiscussions_Create($Sender)
{
$Session = Gdn::Session();
$Sender->Form = new Gdn_Form();
$Sender->Title(T('Merge Discussions'));
$DiscussionModel = new DiscussionModel();
$CheckedDiscussions = Gdn::UserModel()->GetAttribute($Session->User->UserID, 'CheckedDiscussions', array());
if (!is_array($CheckedDiscussions)) {
$CheckedDiscussions = array();
}
$DiscussionIDs = $CheckedDiscussions;
$Sender->SetData('DiscussionIDs', $DiscussionIDs);
$CountCheckedDiscussions = count($DiscussionIDs);
$Sender->SetData('CountCheckedDiscussions', $CountCheckedDiscussions);
$Discussions = $DiscussionModel->SQL->WhereIn('DiscussionID', $DiscussionIDs)->Get('Discussion')->ResultArray();
$Sender->SetData('Discussions', $Discussions);
// Perform the merge
if ($Sender->Form->AuthenticatedPostBack()) {
// Create a new discussion record
$MergeDiscussion = FALSE;
$MergeDiscussionID = $Sender->Form->GetFormValue('MergeDiscussionID');
foreach ($Discussions as $Discussion) {
if ($Discussion['DiscussionID'] == $MergeDiscussionID) {
$MergeDiscussion = $Discussion;
break;
}
}
$RedirectLink = $Sender->Form->GetFormValue('RedirectLink');
if ($MergeDiscussion) {
$ErrorCount = 0;
// Verify that the user has permission to perform the merge.
$Category = CategoryModel::Categories($MergeDiscussion['CategoryID']);
if ($Category && !$Category['PermsDiscussionsEdit']) {
throw PermissionException('Vanilla.Discussions.Edit');
}
$DiscussionModel->DefineSchema();
$MaxNameLength = GetValue('Length', $DiscussionModel->Schema->GetField('Name'));
// Assign the comments to the new discussion record
$DiscussionModel->SQL->Update('Comment')->Set('DiscussionID', $MergeDiscussionID)->WhereIn('DiscussionID', $DiscussionIDs)->Put();
$CommentModel = new CommentModel();
foreach ($Discussions as $Discussion) {
if ($Discussion['DiscussionID'] == $MergeDiscussionID) {
continue;
}
// Create a comment out of the discussion.
$Comment = ArrayTranslate($Discussion, array('Body', 'Format', 'DateInserted', 'InsertUserID', 'InsertIPAddress', 'DateUpdated', 'UpdateUserID', 'UpdateIPAddress', 'Attributes', 'Spam', 'Likes', 'Abuse'));
$Comment['DiscussionID'] = $MergeDiscussionID;
$CommentModel->Validation->Results(TRUE);
$CommentID = $CommentModel->Save($Comment);
if ($CommentID) {
// Move any attachments (FileUpload plugin awareness)
if (class_exists('MediaModel')) {
$MediaModel = new MediaModel();
$MediaModel->Reassign($Discussion['DiscussionID'], 'discussion', $CommentID, 'comment');
}
if ($RedirectLink) {
// The discussion needs to be changed to a moved link.
$RedirectDiscussion = array('Name' => SliceString(sprintf(T('Merged: %s'), $Discussion['Name']), $MaxNameLength), 'Type' => 'redirect', 'Body' => FormatString(T('This discussion has been <a href="{url,html}">merged</a>.'), array('url' => DiscussionUrl($MergeDiscussion))), 'Format' => 'Html');
$DiscussionModel->SetField($Discussion['DiscussionID'], $RedirectDiscussion);
$CommentModel->UpdateCommentCount($Discussion['DiscussionID']);
$CommentModel->RemovePageCache($Discussion['DiscussionID']);
} else {
// Delete discussion that was merged.
$DiscussionModel->Delete($Discussion['DiscussionID']);
}
} else {
$Sender->InformMessage($CommentModel->Validation->ResultsText());
$ErrorCount++;
}
}
// Update counts on all affected discussions.
$CommentModel->UpdateCommentCount($MergeDiscussionID);
$CommentModel->RemovePageCache($MergeDiscussionID);
// Clear selections
Gdn::UserModel()->SaveAttribute($Session->UserID, 'CheckedDiscussions', FALSE);
ModerationController::InformCheckedDiscussions($Sender);
if ($ErrorCount == 0) {
$Sender->JsonTarget('', '', 'Refresh');
}
}
}
$Sender->Render('MergeDiscussions', '', 'plugins/SplitMerge');
}
示例9: foreach
if (!defined('APPLICATION')) {
exit;
}
$Session = Gdn::Session();
$ShowOptions = TRUE;
$Alt = '';
foreach ($this->DraftData->Result() as $Draft) {
$EditUrl = !is_numeric($Draft->DiscussionID) || $Draft->DiscussionID <= 0 ? '/post/editdiscussion/0/' . $Draft->DraftID : '/post/editcomment/0/' . $Draft->DraftID;
$Alt = $Alt == ' Alt' ? '' : ' Alt';
?>
<li class="<?php
echo 'DiscussionRow Draft' . $Alt;
?>
">
<ul>
<li class="Title">
<?php
echo Anchor('Delete', 'vanilla/drafts/delete/' . $Draft->DraftID . '/' . $Session->TransientKey() . '?Target=' . urlencode($this->SelfUrl), 'DeleteDraft');
?>
<strong><?php
echo Anchor($Draft->Name, $EditUrl, 'DraftLink');
?>
</strong>
<?php
echo Anchor(SliceString(Format::Text($Draft->Body), 200), $EditUrl);
?>
</li>
</ul>
</li>
<?php
}
示例10: Gdn_Form_DropDown_Override
public function Gdn_Form_DropDown_Override($Form)
{
$FieldName =& $Form->EventArguments[0];
$DataSet =& $Form->EventArguments[1];
$Attributes =& $Form->EventArguments[2];
//$ValueField = ArrayValueI('ValueField', $Attributes, 'value');
$TextField = ArrayValueI('TextField', $Attributes, 'text');
$MaxDropDownTextField = C('Plugins.Morf.MaxLengthDropDownTextField');
if (GetIncomingValue('DeliveryType', DELIVERY_TYPE_ALL) != DELIVERY_TYPE_ALL) {
$MaxTextLength = GetValue('Window', $MaxDropDownTextField);
} else {
$MaxTextLength = GetValue('Default', $MaxDropDownTextField);
}
if (is_numeric($MaxTextLength) && $MaxTextLength > 0) {
if (is_object($DataSet)) {
$TestValue = GetValue($TextField, $DataSet->FirstRow());
if ($TestValue !== False) {
foreach ($DataSet->ResultObject() as $Data) {
$S = SliceString(GetValue($TextField, $Data), $MaxTextLength);
SetValue($TextField, $Data, $S);
}
}
} elseif (is_array($DataSet)) {
// ResultSet is unexpected here
foreach ($DataSet as &$Value) {
$Value = SliceString($Value, $MaxTextLength);
}
}
}
return $Form->DropDown($FieldName, $DataSet, $Attributes);
}
示例11: WriteTable
function WriteTable($Results, $WriteText, $CssClass)
{
$String = '';
$Total = sizeof($Results);
if ($Total == 0) {
return $String;
//return an empty string if no results
}
$Count = 0;
//for toggling the message div if text
ob_start();
?>
<div class="SphinxSearch Table">
<table>
<thead>
<tr>
<th class="Title">Discussion</th>
<th class="Starter">Starter</th>
<th class="Forum">Forum</th>
<th class="InfoCount">R / V</th>
<th class="Latest">Latest</th>
</tr>
</thead>
<tbody>
<?php
foreach ($Results as $Row) {
?>
<?php
$ID = 'T_' . $Count++;
//unique identifer
$OAuthor->Name = $Row->UserName;
$OAuthor->UserID = $Row->UserID;
//original author
$LAuthor->Name = $Row->LastUserName;
$LAuthor->UserID = $Row->LastUserID;
//latest author
$Row->CountCommentWatch = $Row->CountComments;
//for discussion link
$TitleURL = $Row->IsComment ? 'discussion/comment/' . $Row->CommentID . '/#Comment_' . $Row->CommentID : DiscussionLink($Row, FALSE);
//if the comment is from the orignal discussion poster, simply link to the front page of that
?>
<tr <?php
echo Alternate();
?>
>
<td class="Title">
<?php
if ($WriteText) {
?>
<span id="<?php
echo $ID;
?>
" class="PlusImage Toggle"></span>
<?php
}
?>
<span class="Title"><?php
echo Anchor($Row->Title . Wrap(htmlspecialchars(SliceString($Row->DiscussionBody, SS_PREVIEW_BODY_LIMIT)), 'span', array('class' => 'ToolTip')), $TitleURL, FALSE, array('class' => 'HasToolTip'));
?>
</span>
</td>
<td class="Starter">
<?php
echo UserAnchor($OAuthor);
?>
<?php
Anchor(Gdn_Format::Date($Row->DateInserted), $TitleURL);
?>
</td>
<td class="Forum">
<?php
echo Anchor(Gdn_Format::Text($Row->CatName), 'categories/' . $Row->CatUrlCode);
?>
</td>
<td class="InfoCount">
<?php
echo Gdn_Format::BigNumber($Row->CountComments);
?>
/
<?php
echo Gdn_Format::BigNumber($Row->CountViews);
?>
</td>
<td class="Latest">
<?php
echo UserAnchor($LAuthor) . ' on ';
echo Anchor(Gdn_Format::Date($Row->DateInserted), DiscussionLink($Row, $Extended = TRUE));
?>
</td>
</tr>
<?php
if ($WriteText) {
?>
<tr id="<?php
echo $ID . 'T';
?>
" style="display: none" class="ExpandText">
<td colspan="5"> <!-- Need this since this column will expand the width of the table !-->
<div class="Message Excerpt">
//.........这里部分代码省略.........
示例12: confirmDiscussionMoves
/**
* Form to ask for the destination of the move, confirmation and permission check.
*/
public function confirmDiscussionMoves($DiscussionID = null)
{
$Session = Gdn::session();
$this->Form = new Gdn_Form();
$DiscussionModel = new DiscussionModel();
$CategoryModel = new CategoryModel();
$this->title(t('Confirm'));
if ($DiscussionID) {
$CheckedDiscussions = (array) $DiscussionID;
$ClearSelection = false;
} else {
$CheckedDiscussions = Gdn::userModel()->getAttribute($Session->User->UserID, 'CheckedDiscussions', array());
if (!is_array($CheckedDiscussions)) {
$CheckedDiscussions = array();
}
$ClearSelection = true;
}
$DiscussionIDs = $CheckedDiscussions;
$CountCheckedDiscussions = count($DiscussionIDs);
$this->setData('CountCheckedDiscussions', $CountCheckedDiscussions);
// Check for edit permissions on each discussion
$AllowedDiscussions = array();
$DiscussionData = $DiscussionModel->SQL->select('DiscussionID, Name, DateLastComment, CategoryID, CountComments')->from('Discussion')->whereIn('DiscussionID', $DiscussionIDs)->get();
$DiscussionData = Gdn_DataSet::Index($DiscussionData->resultArray(), array('DiscussionID'));
foreach ($DiscussionData as $DiscussionID => $Discussion) {
$Category = CategoryModel::categories($Discussion['CategoryID']);
if ($Category && $Category['PermsDiscussionsEdit']) {
$AllowedDiscussions[] = $DiscussionID;
}
}
$this->setData('CountAllowed', count($AllowedDiscussions));
$CountNotAllowed = $CountCheckedDiscussions - count($AllowedDiscussions);
$this->setData('CountNotAllowed', $CountNotAllowed);
if ($this->Form->authenticatedPostBack()) {
// Retrieve the category id
$CategoryID = $this->Form->getFormValue('CategoryID');
$Category = CategoryModel::categories($CategoryID);
$RedirectLink = $this->Form->getFormValue('RedirectLink');
// User must have add permission on the target category
if (!$Category['PermsDiscussionsAdd']) {
throw forbiddenException('@' . t('You do not have permission to add discussions to this category.'));
}
$AffectedCategories = array();
// Iterate and move.
foreach ($AllowedDiscussions as $DiscussionID) {
$Discussion = val($DiscussionID, $DiscussionData);
// Create the shadow redirect.
if ($RedirectLink) {
$DiscussionModel->defineSchema();
$MaxNameLength = val('Length', $DiscussionModel->Schema->GetField('Name'));
$RedirectDiscussion = array('Name' => SliceString(sprintf(t('Moved: %s'), $Discussion['Name']), $MaxNameLength), 'DateInserted' => $Discussion['DateLastComment'], 'Type' => 'redirect', 'CategoryID' => $Discussion['CategoryID'], 'Body' => formatString(t('This discussion has been <a href="{url,html}">moved</a>.'), array('url' => DiscussionUrl($Discussion))), 'Format' => 'Html', 'Closed' => true);
// Pass a forced input formatter around this exception.
if (c('Garden.ForceInputFormatter')) {
$InputFormat = c('Garden.InputFormatter');
saveToConfig('Garden.InputFormatter', 'Html', false);
}
$RedirectID = $DiscussionModel->save($RedirectDiscussion);
// Reset the input formatter
if (c('Garden.ForceInputFormatter')) {
saveToConfig('Garden.InputFormatter', $InputFormat, false);
}
if (!$RedirectID) {
$this->Form->setValidationResults($DiscussionModel->validationResults());
break;
}
}
$DiscussionModel->setField($DiscussionID, 'CategoryID', $CategoryID);
if (!isset($AffectedCategories[$Discussion['CategoryID']])) {
$AffectedCategories[$Discussion['CategoryID']] = array(-1, -$Discussion['CountComments']);
} else {
$AffectedCategories[$Discussion['CategoryID']][0] -= 1;
$AffectedCategories[$Discussion['CategoryID']][1] -= $Discussion['CountComments'];
}
if (!isset($AffectedCategories[$CategoryID])) {
$AffectedCategories[$CategoryID] = array(1, $Discussion['CountComments']);
} else {
$AffectedCategories[$CategoryID][0] += 1;
$AffectedCategories[$CategoryID][1] += $Discussion['CountComments'];
}
}
// Update recent posts and counts on all affected categories.
foreach ($AffectedCategories as $CategoryID => $Counts) {
$CategoryModel->SetRecentPost($CategoryID);
$CategoryModel->SQL->update('Category')->set('CountDiscussions', 'CountDiscussions' . ($Counts[0] < 0 ? ' - ' : ' + ') . abs($Counts[0]), false)->set('CountComments', 'CountComments' . ($Counts[1] < 0 ? ' - ' : ' + ') . abs($Counts[1]), false)->where('CategoryID', $CategoryID)->put();
}
// Clear selections.
if ($ClearSelection) {
Gdn::userModel()->saveAttribute($Session->UserID, 'CheckedDiscussions', false);
ModerationController::InformCheckedDiscussions($this);
}
if ($this->Form->errorCount() == 0) {
$this->jsonTarget('', '', 'Refresh');
}
}
$this->render();
}
示例13: SearchExcerpt
function SearchExcerpt($PlainText, $SearchTerms, $Length = 200, $Mark = true)
{
if (empty($SearchTerms)) {
return substrWord($PlainText, 0, $Length);
}
if (is_string($SearchTerms)) {
$SearchTerms = preg_split('`[\\s|-]+`i', $SearchTerms);
}
// Split the string into lines.
$Lines = explode("\n", $PlainText);
// Find the first line that includes a search term.
foreach ($Lines as $i => &$Line) {
$Line = trim($Line);
if (!$Line) {
continue;
}
foreach ($SearchTerms as $Term) {
if (!$Term) {
continue;
}
if (($Pos = mb_stripos($Line, $Term)) !== FALSE) {
$Line = substrWord($Line, $Term, $Length);
// if ($Pos + mb_strlen($Term) > $Length) {
// $St = -(strlen($Line) - ($Pos - $Length / 4));
// $Pos2 = strrpos($Line, ' ', $St);
// if ($Pos2 !== FALSE)
// $Line = '…'.substrWord($Line, $Pos2, $Length, "!!!");
// else
// $Line = '…!'.mb_substr($Line, $St, $Length);
// } else {
// $Line = substrWord($Line, 0, $Length, '---');
// }
return MarkString($SearchTerms, $Line);
}
}
}
// No line was found so return the first non-blank line.
foreach ($Lines as $Line) {
if ($Line) {
return SliceString($Line, $Length);
}
}
}
示例14: panelHeading
if (!defined('APPLICATION')) {
exit;
}
?>
<div class="Box BoxDrafts">
<?php
echo panelHeading(T('My Drafts'));
?>
<ul class="PanelInfo PanelDiscussions">
<?php
foreach ($this->Data->Result() as $Draft) {
$EditUrl = !is_numeric($Draft->DiscussionID) || $Draft->DiscussionID <= 0 ? '/post/editdiscussion/0/' . $Draft->DraftID : '/post/editcomment/0/' . $Draft->DraftID;
?>
<li>
<strong><?php
echo Anchor($Draft->Name, $EditUrl);
?>
</strong>
<?php
echo Anchor(SliceString(Gdn_Format::Text($Draft->Body), 200), $EditUrl, 'DraftCommentLink');
?>
</li>
<?php
}
?>
<li class="ShowAll"><?php
echo Anchor(T('↳ Show All'), 'drafts');
?>
</li>
</ul>
</div>
示例15: WriteClassic
function WriteClassic($Results, $WriteText, $CssClass)
{
if (sizeof($Results) == 0) {
//make sure there is something here
return '';
}
ob_start();
?>
<div class="SphinxSearch">
<ul class="DataList">
<?php
foreach ($Results as $Row) {
?>
<?php
$Author->Photo = $Row->UserPhoto;
$Author->Name = $Row->UserName;
$Author->UserID = $Row->UserID;
$TitleURL = $Row->IsComment ? 'discussion/comment/' . $Row->CommentID . '/#Comment_' . $Row->CommentID : DiscussionLink($Row, FALSE);
//if the comment is from the orignal discussion poster, simply link to the front page of that
?>
<li class="Item">
<div class="ItemContent">
<h4 class="Title"><?php
echo Anchor($Row->Title, $TitleURL, FALSE, array('class' => 'HasToolTip'));
?>
</h4>
<?php
if ($WriteText) {
?>
<div class="Message Excerpt">
<?php
//echo nl2br(SliceString($Row->Body, SS_BODY_LIMIT)); This seemed to make MARKDOWN posts look correct - JJB
?>
<?php
echo SliceString($Row->Body, SS_BODY_LIMIT);
?>
</div>
<?php
}
?>
<div class="Meta">
<span class="MItem"><?php
echo UserPhoto($Author, array('LinkClass' => '', 'ImageClass' => 'ProfilePhotoSmall PhotoWrap'));
?>
</span>
<span class="MItem"><?php
echo Anchor($Row->UserName, UserUrl($Author));
?>
</span>
<span class="MItem"><?php
echo Anchor(Gdn_Format::Date($Row->DateInserted), 'discussion/' . $Row->DiscussionID . '/' . Gdn_Format::Url($Row->Title) . '/p1');
?>
</span>
<span class="MItem"><?php
echo Anchor($Row->CatName, 'discussion/' . $Row->DiscussionID . '/' . Gdn_Format::Url($Row->Title) . '/p1');
?>
</span>
</div>
</div>
</li>
<?php
}
?>
</ul>
</div>
<?php
$String = ob_get_contents();
@ob_end_clean();
return $String;
}