本文整理汇总了PHP中Gdn_Format::PlainText方法的典型用法代码示例。如果您正苦于以下问题:PHP Gdn_Format::PlainText方法的具体用法?PHP Gdn_Format::PlainText怎么用?PHP Gdn_Format::PlainText使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Gdn_Format
的用法示例。
在下文中一共展示了Gdn_Format::PlainText方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: AddLabel
public function AddLabel($Name, $Code = '', $Url = '')
{
if ($Code == '') {
$Code = Gdn_Format::Url(ucwords(trim(Gdn_Format::PlainText($Name))));
}
$this->_Labels[] = array('Name' => $Name, 'Code' => $Code, 'Url' => $Url);
}
示例2: Post
public function Post($Notify = FALSE, $UserID = FALSE)
{
if (is_numeric($Notify)) {
$UserID = $Notify;
$Notify = FALSE;
}
if (!$UserID) {
$UserID = Gdn::Session()->UserID;
}
switch ($Notify) {
case 'mods':
$this->Permission('Garden.Moderation.Manage');
$NotifyUserID = ActivityModel::NOTIFY_MODS;
break;
case 'admins':
$this->Permission('Garden.Settings.Manage');
$NotifyUserID = ActivityModel::NOTIFY_ADMINS;
break;
default:
$this->Permission('Garden.Profiles.Edit');
$NotifyUserID = ActivityModel::NOTIFY_PUBLIC;
break;
}
$Activities = array();
if ($this->Form->IsPostBack()) {
$Data = $this->Form->FormValues();
$Data = $this->ActivityModel->FilterForm($Data);
if (!isset($Data['Format']) || strcasecmp($Data['Format'], 'Raw') == 0) {
$Data['Format'] = C('Garden.InputFormatter');
}
if ($UserID != Gdn::Session()->UserID) {
// This is a wall post.
$Activity = array('ActivityType' => 'WallPost', 'ActivityUserID' => $UserID, 'RegardingUserID' => Gdn::Session()->UserID, 'HeadlineFormat' => T('HeadlineFormat.WallPost', '{RegardingUserID,you} → {ActivityUserID,you}'), 'Story' => $Data['Comment'], 'Format' => $Data['Format']);
} else {
// This is a status update.
$Activity = array('ActivityType' => 'Status', 'HeadlineFormat' => T('HeadlineFormat.Status', '{ActivityUserID,user}'), 'Story' => $Data['Comment'], 'Format' => $Data['Format'], 'NotifyUserID' => $NotifyUserID);
$this->SetJson('StatusMessage', Gdn_Format::PlainText($Activity['Story'], $Activity['Format']));
}
$Activity = $this->ActivityModel->Save($Activity, FALSE, array('CheckSpam' => TRUE));
if ($Activity == SPAM || $Activity == UNAPPROVED) {
$this->StatusMessage = T('ActivityRequiresApproval', 'Your post will appear after it is approved.');
$this->Render('Blank', 'Utility');
return;
}
if ($Activity) {
if ($UserID == Gdn::Session()->UserID && $NotifyUserID == ActivityModel::NOTIFY_PUBLIC) {
Gdn::UserModel()->SetField(Gdn::Session()->UserID, 'About', Gdn_Format::PlainText($Activity['Story'], $Activity['Format']));
}
$Activities = array($Activity);
ActivityModel::JoinUsers($Activities);
$this->ActivityModel->CalculateData($Activities);
} else {
$this->Form->SetValidationResults($this->ActivityModel->ValidationResults());
$this->StatusMessage = $this->ActivityModel->Validation->ResultsText();
// $this->Render('Blank', 'Utility');
}
}
if ($this->DeliveryType() == DELIVERY_TYPE_ALL) {
Redirect($this->Request->Get('Target', '/activity'));
}
$this->SetData('Activities', $Activities);
$this->Render('Activities');
}
示例3: FormatMeAction
function FormatMeAction($Comment)
{
if (!IsMeAction($Comment)) {
return;
}
// Maxlength (don't let people blow up the forum)
$Maxlength = C('Vanilla.MeAction.MaxLength', 100);
$Body = Gdn_Format::PlainText(substr($Comment->Body, 4));
if (strlen($Body) > $Maxlength) {
$Body = substr($Body, 0, $Maxlength) . '...';
}
return '<div class="AuthorAction">' . $Body . '</div>';
}
示例4: Url
?>
<li class="Item" rel="<?php
echo Url("/messages/{$Row['ConversationID']}#latest");
?>
">
<div class="Author Photo"><?php
echo UserPhoto($PhotoUser);
?>
</div>
<div class="ItemContent">
<b class="Subject"><?php
echo Anchor($Subject, "/messages/{$Row['ConversationID']}#latest");
?>
</b>
<?php
$Excerpt = SliceString(Gdn_Format::PlainText($Row['LastBody'], $Row['LastFormat']), 80);
echo Wrap(nl2br($Excerpt), 'div', array('class' => 'Excerpt'));
?>
<div class="Meta">
<?php
echo ' <span class="MItem">' . Plural($Row['CountMessages'], '%s message', '%s messages') . '</span> ';
if ($Row['CountNewMessages'] > 0) {
echo ' <strong class="HasNew"> ' . Plural($Row['CountNewMessages'], '%s new', '%s new') . '</strong> ';
}
echo ' <span class="MItem">' . Gdn_Format::Date($Row['LastDateInserted']) . '</span> ';
?>
</div>
</div>
</li>
<?php
}
示例5: Email
public function Email(&$Activity, $NoDelete = FALSE)
{
if (is_numeric($Activity)) {
$ActivityID = $Activity;
$Activity = $this->GetID($ActivityID);
} else {
$ActivityID = GetValue('ActivityID', $Activity);
}
if (!$Activity) {
return FALSE;
}
$Activity = (array) $Activity;
$User = Gdn::UserModel()->GetID($Activity['NotifyUserID'], DATASET_TYPE_ARRAY);
if (!$User) {
return FALSE;
}
// Format the activity headline based on the user being emailed.
if (GetValue('HeadlineFormat', $Activity)) {
$SessionUserID = Gdn::Session()->UserID;
Gdn::Session()->UserID = $User['UserID'];
$Activity['Headline'] = FormatString($Activity['HeadlineFormat'], $Activity);
Gdn::Session()->UserID = $SessionUserID;
} else {
if (!isset($Activity['ActivityGender'])) {
$AT = self::GetActivityType($Activity['ActivityType']);
$Data = array($Activity);
self::JoinUsers($Data);
$Activity = $Data[0];
$Activity['RouteCode'] = GetValue('RouteCode', $AT);
$Activity['FullHeadline'] = GetValue('FullHeadline', $AT);
$Activity['ProfileHeadline'] = GetValue('ProfileHeadline', $AT);
}
$Activity['Headline'] = Gdn_Format::ActivityHeadline($Activity, '', $User['UserID']);
}
// Build the email to send.
$Email = new Gdn_Email();
$Email->Subject(sprintf(T('[%1$s] %2$s'), C('Garden.Title'), Gdn_Format::PlainText($Activity['Headline'])));
$Email->To($User);
$Url = ExternalUrl($Activity['Route'] == '' ? '/' : $Activity['Route']);
if ($Activity['Story']) {
$Message = sprintf(T('EmailStoryNotification', "%3\$s\n\n%2\$s"), Gdn_Format::PlainText($Activity['Headline']), $Url, Gdn_Format::PlainText($Activity['Story']));
} else {
$Message = sprintf(T('EmailNotification', "%1\$s\n\n%2\$s"), Gdn_Format::PlainText($Activity['Headline']), $Url);
}
$Email->Message($Message);
// Fire an event for the notification.
$Notification = array('ActivityID' => $ActivityID, 'User' => $User, 'Email' => $Email, 'Route' => $Activity['Route'], 'Story' => $Activity['Story'], 'Headline' => $Activity['Headline'], 'Activity' => $Activity);
$this->EventArguments = $Notification;
$this->FireEvent('BeforeSendNotification');
// Send the email.
try {
// Only send if the user is not banned
if (!GetValue('Banned', $User)) {
$Email->Send();
}
$Emailed = self::SENT_OK;
// Delete the activity now that it has been emailed.
if (!$NoDelete && !$Activity['Notified']) {
if (GetValue('ActivityID', $Activity)) {
$this->Delete($Activity['ActivityID']);
} else {
$Activity['_Delete'] = TRUE;
}
}
} catch (phpmailerException $pex) {
if ($pex->getCode() == PHPMailer::STOP_CRITICAL) {
$Emailed = self::SENT_FAIL;
} else {
$Emailed = self::SENT_ERROR;
}
} catch (Exception $ex) {
$Emailed = self::SENT_FAIL;
// similar to http 5xx
}
$Activity['Emailed'] = $Emailed;
if ($ActivityID) {
// Save the emailed flag back to the activity.
$this->SQL->Put('Activity', array('Emailed' => $Emailed), array('ActivityID' => $ActivityID));
}
}
示例6: Description
public function Description($Value = FALSE, $PlainText = FALSE)
{
if ($Value != FALSE) {
if ($PlainText) {
$Value = Gdn_Format::PlainText($Value);
}
$this->SetData('_Description', $Value);
}
return $this->Data('_Description');
}
示例7: Index
/**
* Default single discussion display.
*
* @since 2.0.0
* @access public
*
* @param int $DiscussionID Unique discussion ID
* @param string $DiscussionStub URL-safe title slug
* @param int $Page The current page of comments
*/
public function Index($DiscussionID = '', $DiscussionStub = '', $Page = '')
{
// Setup head
$Session = Gdn::Session();
$this->AddJsFile('jquery.autogrow.js');
$this->AddJsFile('discussion.js');
$this->AddJsFile('autosave.js');
Gdn_Theme::Section('Discussion');
// Load the discussion record
$DiscussionID = is_numeric($DiscussionID) && $DiscussionID > 0 ? $DiscussionID : 0;
if (!array_key_exists('Discussion', $this->Data)) {
$this->SetData('Discussion', $this->DiscussionModel->GetID($DiscussionID), TRUE);
}
if (!is_object($this->Discussion)) {
throw new Exception(sprintf(T('%s Not Found'), T('Discussion')), 404);
}
// Define the query offset & limit.
$Limit = C('Vanilla.Comments.PerPage', 30);
$OffsetProvided = $Page != '';
list($Offset, $Limit) = OffsetLimit($Page, $Limit);
// Check permissions
$this->Permission('Vanilla.Discussions.View', TRUE, 'Category', $this->Discussion->PermissionCategoryID);
$this->SetData('CategoryID', $this->CategoryID = $this->Discussion->CategoryID, TRUE);
$this->SetData('Breadcrumbs', CategoryModel::GetAncestors($this->CategoryID));
$Category = CategoryModel::Categories($this->Discussion->CategoryID);
if ($CategoryCssClass = GetValue('CssClass', $Category)) {
Gdn_Theme::Section($CategoryCssClass);
}
// Setup
$this->Title($this->Discussion->Name);
// Actual number of comments, excluding the discussion itself.
$ActualResponses = $this->Discussion->CountComments;
$this->Offset = $Offset;
if (C('Vanilla.Comments.AutoOffset')) {
// if ($this->Discussion->CountCommentWatch > 1 && $OffsetProvided == '')
// $this->AddDefinition('ScrollTo', 'a[name=Item_'.$this->Discussion->CountCommentWatch.']');
if (!is_numeric($this->Offset) || $this->Offset < 0 || !$OffsetProvided) {
// Round down to the appropriate offset based on the user's read comments & comments per page
$CountCommentWatch = $this->Discussion->CountCommentWatch > 0 ? $this->Discussion->CountCommentWatch : 0;
if ($CountCommentWatch > $ActualResponses) {
$CountCommentWatch = $ActualResponses;
}
// (((67 comments / 10 perpage) = 6.7) rounded down = 6) * 10 perpage = offset 60;
$this->Offset = floor($CountCommentWatch / $Limit) * $Limit;
}
if ($ActualResponses <= $Limit) {
$this->Offset = 0;
}
if ($this->Offset == $ActualResponses) {
$this->Offset -= $Limit;
}
} else {
if ($this->Offset == '') {
$this->Offset = 0;
}
}
if ($this->Offset < 0) {
$this->Offset = 0;
}
$LatestItem = $this->Discussion->CountCommentWatch;
if ($LatestItem === NULL) {
$LatestItem = 0;
} elseif ($LatestItem < $this->Discussion->CountComments) {
$LatestItem += 1;
}
$this->SetData('_LatestItem', $LatestItem);
// Set the canonical url to have the proper page title.
$this->CanonicalUrl(DiscussionUrl($this->Discussion, PageNumber($this->Offset, $Limit, 0, FALSE)));
// Url(ConcatSep('/', 'discussion/'.$this->Discussion->DiscussionID.'/'. Gdn_Format::Url($this->Discussion->Name), PageNumber($this->Offset, $Limit, TRUE, Gdn::Session()->UserID != 0)), TRUE), Gdn::Session()->UserID == 0);
// Load the comments
$this->SetData('Comments', $this->CommentModel->Get($DiscussionID, $Limit, $this->Offset));
$PageNumber = PageNumber($this->Offset, $Limit);
$this->SetData('Page', $PageNumber);
$this->_SetOpenGraph();
include_once PATH_LIBRARY . '/vendors/simplehtmldom/simple_html_dom.php';
if ($PageNumber == 1) {
$this->Description(SliceParagraph(Gdn_Format::PlainText($this->Discussion->Body, $this->Discussion->Format), 160));
// Add images to head for open graph
$Dom = str_get_html(Gdn_Format::To($this->Discussion->Body, $this->Discussion->Format));
} else {
$this->Data['Title'] .= sprintf(T(' - Page %s'), PageNumber($this->Offset, $Limit));
$FirstComment = $this->Data('Comments')->FirstRow();
$FirstBody = GetValue('Body', $FirstComment);
$FirstFormat = GetValue('Format', $FirstComment);
$this->Description(SliceParagraph(Gdn_Format::PlainText($FirstBody, $FirstFormat), 160));
// Add images to head for open graph
$Dom = str_get_html(Gdn_Format::To($FirstBody, $FirstFormat));
}
if ($Dom) {
foreach ($Dom->find('img') as $img) {
//.........这里部分代码省略.........
示例8: Image
/**
* Format a serialized string of image properties as html.
* @param string $Body a serialized array of image properties (Image, Thumbnail, Caption)
*/
public static function Image($Body)
{
if (is_string($Body)) {
$Image = @unserialize($Body);
if (!$Image) {
return Gdn_Format::Html($Body);
}
}
$Url = GetValue('Image', $Image);
$Caption = Gdn_Format::PlainText(GetValue('Caption', $Image));
return '<div class="ImageWrap">' . '<div class="Image">' . Img($Url, array('alt' => $Caption, 'title' => $Caption)) . '</div>' . '<div class="Caption">' . $Caption . '</div>' . '</div>';
}
示例9: PostController_Twitter_Create
/**
*
* @param PostController $Sender
* @param type $RecordType
* @param type $ID
* @throws type
*/
public function PostController_Twitter_Create($Sender, $RecordType, $ID)
{
if (!$this->SocialReactions()) {
throw PermissionException();
}
// if (!Gdn::Request()->IsPostBack())
// throw PermissionException('Javascript');
$Row = GetRecord($RecordType, $ID);
if ($Row) {
// Grab the tweet message.
switch (strtolower($RecordType)) {
case 'discussion':
$Message = Gdn_Format::PlainText($Row['Name'], 'Text');
break;
case 'comment':
default:
$Message = Gdn_Format::PlainText($Row['Body'], $Row['Format']);
}
$Elips = '...';
$Message = preg_replace('`\\s+`', ' ', $Message);
// if (function_exists('normalizer_is_normalized')) {
// // Slice the string to 119 characters (21 reservered for the url.
// if (!normalizer_is_normalized($Message))
// $Message = Normalizer::normalize($Message, Normalizer::FORM_D);
// $Elips = Normalizer::normalize($Elips, Normalizer::FORM_D);
// }
$Max = 140;
$LinkLen = 22;
$Max -= $LinkLen;
$Message = SliceParagraph($Message, $Max);
if (strlen($Message) > $Max) {
$Message = substr($Message, 0, $Max - strlen($Elips)) . $Elips;
}
// echo $Message.strlen($Message);
if ($this->AccessToken()) {
Gdn::Controller()->SetData('Message', $Message);
$Message .= ' ' . $Row['ShareUrl'];
$R = $this->API('/statuses/update.json', array('status' => $Message), 'POST');
$Sender->SetJson('R', $R);
$Sender->InformMessage(T('Thanks for sharing!'));
} else {
$Get = array('text' => $Message, 'url' => $Row['ShareUrl']);
$Url = "http://twitter.com/share?" . http_build_query($Get);
Redirect($Url);
}
}
$Sender->Render('Blank', 'Utility', 'Dashboard');
}
示例10: Index
/**
* Default search functionality.
*
* @since 2.0.0
* @access public
* @param int $Page Page number.
*/
public function Index($Page = '')
{
$this->AddJsFile('search.js');
$this->Title(T('Search'));
SaveToConfig('Garden.Format.EmbedSize', '160x90', FALSE);
Gdn_Theme::Section('SearchResults');
list($Offset, $Limit) = OffsetLimit($Page, C('Garden.Search.PerPage', 20));
$this->SetData('_Limit', $Limit);
$Search = $this->Form->GetFormValue('Search');
$Mode = $this->Form->GetFormValue('Mode');
if ($Mode) {
$this->SearchModel->ForceSearchMode = $Mode;
}
try {
$ResultSet = $this->SearchModel->Search($Search, $Offset, $Limit);
} catch (Gdn_UserException $Ex) {
$this->Form->AddError($Ex);
$ResultSet = array();
} catch (Exception $Ex) {
LogException($Ex);
$this->Form->AddError($Ex);
$ResultSet = array();
}
Gdn::UserModel()->JoinUsers($ResultSet, array('UserID'));
// Fix up the summaries.
$SearchTerms = explode(' ', Gdn_Format::Text($Search));
foreach ($ResultSet as &$Row) {
$Row['Summary'] = SearchExcerpt(Gdn_Format::PlainText($Row['Summary'], $Row['Format']), $SearchTerms);
$Row['Summary'] = Emoji::instance()->translateToHtml($Row['Summary']);
$Row['Format'] = 'Html';
}
$this->SetData('SearchResults', $ResultSet, TRUE);
$this->SetData('SearchTerm', Gdn_Format::Text($Search), TRUE);
if ($ResultSet) {
$NumResults = count($ResultSet);
} else {
$NumResults = 0;
}
if ($NumResults == $Offset + $Limit) {
$NumResults++;
}
// Build a pager
$PagerFactory = new Gdn_PagerFactory();
$this->Pager = $PagerFactory->GetPager('MorePager', $this);
$this->Pager->MoreCode = 'More Results';
$this->Pager->LessCode = 'Previous Results';
$this->Pager->ClientID = 'Pager';
$this->Pager->Configure($Offset, $Limit, $NumResults, 'dashboard/search/%1$s/%2$s/?Search=' . Gdn_Format::Url($Search));
// if ($this->_DeliveryType != DELIVERY_TYPE_ALL) {
// $this->SetJson('LessRow', $this->Pager->ToString('less'));
// $this->SetJson('MoreRow', $this->Pager->ToString('more'));
// $this->View = 'results';
// }
$this->CanonicalUrl(Url('search', TRUE));
$this->Render();
}
示例11: writePromotedContent
/**
* Generates html output of $Content array
*
* @param array|object $Content
* @param PromotedContentModule $Sender
*/
function writePromotedContent($Content, $Sender)
{
static $UserPhotoFirst = NULL;
if ($UserPhotoFirst === null) {
$UserPhotoFirst = c('Vanilla.Comment.UserPhotoFirst', true);
}
$ContentType = val('RecordType', $Content);
$ContentID = val("{$ContentType}ID", $Content);
$Author = val('Author', $Content);
$ContentURL = val('Url', $Content);
$Sender->EventArguments['Content'] =& $Content;
$Sender->EventArguments['ContentUrl'] =& $ContentURL;
?>
<div id="<?php
echo "Promoted_{$ContentType}_{$ContentID}";
?>
" class="<?php
echo CssClass($Content);
?>
">
<div class="AuthorWrap">
<span class="Author">
<?php
if ($UserPhotoFirst) {
echo userPhoto($Author);
echo userAnchor($Author, 'Username');
} else {
echo userAnchor($Author, 'Username');
echo userPhoto($Author);
}
$Sender->fireEvent('AuthorPhoto');
?>
</span>
<span class="AuthorInfo">
<?php
echo ' ' . WrapIf(htmlspecialchars(val('Title', $Author)), 'span', array('class' => 'MItem AuthorTitle'));
echo ' ' . WrapIf(htmlspecialchars(val('Location', $Author)), 'span', array('class' => 'MItem AuthorLocation'));
$Sender->fireEvent('AuthorInfo');
?>
</span>
</div>
<div class="Meta CommentMeta CommentInfo">
<span class="MItem DateCreated">
<?php
echo anchor(Gdn_Format::date($Content['DateInserted'], 'html'), $ContentURL, 'Permalink', array('rel' => 'nofollow'));
?>
</span>
<?php
// Include source if one was set
if ($Source = val('Source', $Content)) {
echo wrap(sprintf(t('via %s'), t($Source . ' Source', $Source)), 'span', array('class' => 'MItem Source'));
}
$Sender->fireEvent('ContentInfo');
?>
</div>
<div
class="Title"><?php
echo anchor(Gdn_Format::text(sliceString($Content['Name'], $Sender->TitleLimit), false), $ContentURL, 'DiscussionLink');
?>
</div>
<div class="Body">
<?php
echo anchor(htmlspecialchars(sliceString(Gdn_Format::PlainText($Content['Body']), $Sender->BodyLimit)), $ContentURL, 'BodyLink');
$Sender->fireEvent('AfterPromotedBody');
// separate event to account for less space.
?>
</div>
</div>
<?php
}
示例12: PostController_Facebook_Create
/**
*
* @param PostController $Sender
* @param type $RecordType
* @param type $ID
* @throws type
*/
public function PostController_Facebook_Create($Sender, $RecordType, $ID)
{
if (!$this->SocialReactions()) {
throw PermissionException();
}
// if (!Gdn::Request()->IsPostBack())
// throw PermissionException('Javascript');
$Row = GetRecord($RecordType, $ID);
if ($Row) {
$Message = SliceParagraph(Gdn_Format::PlainText($Row['Body'], $Row['Format']), 160);
if ($this->AccessToken() && $Sender->Request->IsPostBack()) {
$R = $this->API('/me/feed', array('link' => $Row['ShareUrl'], 'message' => $Message));
$Sender->SetJson('R', $R);
$Sender->InformMessage(T('Thanks for sharing!'));
} else {
// http://www.facebook.com/dialog/feed?app_id=231546166870342&redirect_uri=http%3A%2F%2Fvanillicon.com%2Fredirect%2Ffacebook%3Fhash%3Daad66afb13105676dffa79bfe2b8595f&link=http%3A%2F%2Fvanillicon.com&picture=http%3A%2F%2Fvanillicon.com%2Faad66afb13105676dffa79bfe2b8595f.png&name=Vanillicon&caption=What%27s+Your+Vanillicon+Look+Like%3F&description=Vanillicons+are+unique+avatars+generated+by+your+name+or+email+that+are+free+to+make+%26+use+around+the+web.+Create+yours+now%21
$Get = array('app_id' => C('Plugins.Facebook.ApplicationID'), 'link' => $Row['ShareUrl'], 'name' => Gdn_Format::PlainText($Row['Name'], 'Text'), 'description' => $Message, 'redirect_uri' => Url('/post/shared/facebook', TRUE));
$Url = 'http://www.facebook.com/dialog/feed?' . http_build_query($Get);
Redirect($Url);
}
}
$Sender->Render('Blank', 'Utility', 'Dashboard');
}
示例13: FormatQuote
protected function FormatQuote($Type, $ID, &$QuoteData)
{
$Type = strtolower($Type);
$Model = FALSE;
switch ($Type) {
case 'comment':
$Model = new CommentModel();
break;
case 'discussion':
$Model = new DiscussionModel();
break;
default:
break;
}
//$QuoteData = array();
if ($Model) {
$Data = $Model->GetID($ID);
$NewFormat = C('Garden.InputFormatter');
$QuoteFormat = $Data->Format;
// Perform transcoding if possible
$NewBody = $Data->Body;
if ($QuoteFormat != $NewFormat) {
if ($QuoteFormat == 'BBCode' && $NewFormat == 'Html') {
$NewBody = Gdn_Format::BBCode($NewBody);
} elseif ($QuoteFormat == 'Text' && $NewFormat == 'Html') {
$NewBody = Gdn_Format::Text($NewBody);
} elseif ($QuoteFormat == 'Html' && $NewFormat == 'BBCode') {
$NewBody = Gdn_Format::Text($NewBody);
} elseif ($QuoteFormat == 'Text' && $NewFormat == 'BBCode') {
$NewBody = Gdn_Format::Text($NewBody);
} else {
$NewBody = Gdn_Format::PlainText($NewBody, $QuoteFormat);
}
Gdn::Controller()->InformMessage(sprintf(T('The quote had to be converted from %s to %s.', 'The quote had to be converted from %s to %s. Some formatting may have been lost.'), $QuoteFormat, $NewFormat));
}
$Data->Body = $NewBody;
$QuoteData = array_merge($QuoteData, array('status' => 'success', 'body' => $Data->Body, 'format' => C('Garden.InputFormatter'), 'authorid' => $Data->InsertUserID, 'authorname' => $Data->InsertName, 'type' => $Type, 'typeid' => $ID));
}
}
示例14: FormatQuote
protected function FormatQuote($Type, $ID, &$QuoteData, $Format = FALSE)
{
if (!$Format) {
$Format = C('Garden.InputFormatter');
}
$Type = strtolower($Type);
$Model = FALSE;
switch ($Type) {
case 'comment':
$Model = new CommentModel();
break;
case 'discussion':
$Model = new DiscussionModel();
break;
default:
break;
}
//$QuoteData = array();
if ($Model) {
$Data = $Model->GetID($ID);
$NewFormat = $Format;
if ($NewFormat == 'Wysiwyg') {
$NewFormat = 'Html';
}
$QuoteFormat = $Data->Format;
if ($QuoteFormat == 'Wysiwyg') {
$QuoteFormat = 'Html';
}
// Perform transcoding if possible
$NewBody = $Data->Body;
if ($QuoteFormat != $NewFormat) {
if (in_array($NewFormat, array('Html', 'Wysiwyg'))) {
$NewBody = Gdn_Format::To($NewBody, $QuoteFormat);
} elseif ($QuoteFormat == 'Html' && $NewFormat == 'BBCode') {
$NewBody = Gdn_Format::Text($NewBody);
} elseif ($QuoteFormat == 'Text' && $NewFormat == 'BBCode') {
$NewBody = Gdn_Format::Text($NewBody);
} else {
$NewBody = Gdn_Format::PlainText($NewBody, $QuoteFormat);
}
if (!in_array($NewFormat, array('Html', 'Wysiwyg'))) {
Gdn::Controller()->InformMessage(sprintf(T('The quote had to be converted from %s to %s.', 'The quote had to be converted from %s to %s. Some formatting may have been lost.'), htmlspecialchars($QuoteFormat), htmlspecialchars($NewFormat)));
}
}
$Data->Body = $NewBody;
// Format the quote according to the format.
switch ($Format) {
case 'Html':
// HTML
$Quote = '<blockquote class="Quote" rel="' . htmlspecialchars($Data->InsertName) . '">' . $Data->Body . '</blockquote>' . "\n";
break;
case 'BBCode':
$Author = htmlspecialchars($Data->InsertName);
if ($ID) {
$IDString = ';' . htmlspecialchars($ID);
}
$QuoteBody = $Data->Body;
// TODO: Strip inner quotes...
// $QuoteBody = trim(preg_replace('`(\[quote.*/quote\])`si', '', $QuoteBody));
$Quote = <<<BQ
[quote="{$Author}{$IDString}"]{$QuoteBody}[/quote]
BQ;
break;
case 'Markdown':
case 'Display':
case 'Text':
$QuoteBody = $Data->Body;
// Strip inner quotes and mentions...
$QuoteBody = self::_StripMarkdownQuotes($QuoteBody);
$QuoteBody = self::_StripMentions($QuoteBody);
$Quote = '> ' . sprintf(T('%s said:'), '@' . $Data->InsertName) . "\n" . '> ' . str_replace("\n", "\n> ", $QuoteBody);
break;
case 'Wysiwyg':
$Attribution = sprintf(T('%s said:'), UserAnchor($Data, NULL, array('Px' => 'Insert')));
$QuoteBody = $Data->Body;
// TODO: Strip inner quotes...
// $QuoteBody = trim(preg_replace('`(<blockquote.*/blockquote>)`si', '', $QuoteBody));
$Quote = <<<BLOCKQUOTE
<blockquote class="Quote">
<div class="QuoteAuthor">{$Attribution}</div>
<div class="QuoteText">{$QuoteBody}</div>
</blockquote>
BLOCKQUOTE;
break;
}
$QuoteData = array_merge($QuoteData, array('status' => 'success', 'body' => $Quote, 'format' => $Format, 'authorid' => $Data->InsertUserID, 'authorname' => $Data->InsertName, 'type' => $Type, 'typeid' => $ID));
}
}
示例15: Index
/**
* Loads default page view.
*
* @param string $PageUrlCode ; Unique page URL stub identifier.
*/
public function Index($PageUrlCode = '')
{
$this->Page = $this->PageModel->GetByUrlCode($PageUrlCode);
// Require the custom view permission if it exists.
// Otherwise, the page is public by default.
$ViewPermissionName = 'BasicPages.' . $PageUrlCode . '.View';
if (array_key_exists($ViewPermissionName, Gdn::PermissionModel()->PermissionColumns())) {
$this->Permission($ViewPermissionName);
}
// If page doesn't exist.
if ($this->Page == null) {
throw new Exception(sprintf(T('%s Not Found'), T('Page')), 404);
return null;
}
$this->SetData('Page', $this->Page, false);
// Add body CSS class.
$this->CssClass = 'Page-' . $this->Page->UrlCode;
if (IsMobile()) {
$this->CssClass .= ' PageMobile';
}
// Set the canonical URL to have the proper page link.
$this->CanonicalUrl(PageModel::PageUrl($this->Page));
// Add modules
$this->AddModule('GuestModule');
$this->AddModule('SignedInModule');
// Add CSS files
$this->AddCssFile('page.css');
$this->AddModule('NewDiscussionModule');
$this->AddModule('DiscussionFilterModule');
$this->AddModule('BookmarkedModule');
$this->AddModule('DiscussionsModule');
$this->AddModule('RecentActivityModule');
// Setup head.
if (!$this->Data('Title')) {
$Title = C('Garden.HomepageTitle');
$DefaultControllerDestination = Gdn::Router()->GetDestination('DefaultController');
if ($Title != '' && strpos($DefaultControllerDestination, 'page/' . $this->Page->UrlCode) !== false) {
// If the page is set as DefaultController.
$this->Title($Title, '');
// Add description meta tag.
$this->Description(C('Garden.Description', null));
} else {
// If the page is NOT the DefaultController.
$this->Title($this->Page->Name);
// Add description meta tag.
$this->Description(SliceParagraph(Gdn_Format::PlainText($this->Page->Body, $this->Page->Format), 160));
}
}
$this->Render();
}