本文整理汇总了PHP中Gdn_Format::To方法的典型用法代码示例。如果您正苦于以下问题:PHP Gdn_Format::To方法的具体用法?PHP Gdn_Format::To怎么用?PHP Gdn_Format::To使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Gdn_Format
的用法示例。
在下文中一共展示了Gdn_Format::To方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: Page
public function Page($Reference)
{
$PageModel = new PageModel();
$Page = $PageModel->GetFullID($Reference);
if (!$Page) {
throw NotFoundException();
}
$this->Page = $Page;
if ($this->Head) {
SetMetaTags($Page, $this);
if ($Page->CustomCss) {
$CustomCss = "\n" . $Page->CustomCss;
if (!StringBeginsWith(trim($CustomCss), '<style', True)) {
$CustomCss = Wrap($CustomCss, 'style', array('type' => 'text/css'));
}
$this->Head->AddString($CustomCss);
}
if ($Page->CustomJs) {
$CustomJs = $Page->CustomJs;
if (!StringBeginsWith(trim($CustomJs), '<script', True)) {
$CustomJs = Wrap($CustomJs, 'script', array('type' => 'text/javascript'));
}
$this->Head->AddString($CustomJs);
}
}
if ($Page->SectionID) {
$this->Section = BuildNode($Page, 'Section');
$this->SectionID = $Page->SectionID;
CandyHooks::AddModules($this, $this->Section);
}
$this->FireEvent('ContentPage');
if ($Page->View) {
$this->View = $this->FetchViewLocation($this->View, False, False, False);
}
if (!$this->View) {
$this->View = $this->FetchViewLocation('view', 'page', '', False);
if (!$this->View) {
$this->View = 'default';
}
}
$this->Title($Page->Title);
$this->SetData('Content', $Page, True);
$this->EventArguments['Format'] =& $Page->Format;
$this->EventArguments['Body'] =& $Page->Body;
$this->FireEvent('BeforeBodyFormat');
$this->ContentBodyHtml = Gdn_Format::To($Page->Body, $Page->Format);
$Doc = PqDocument($this->ContentBodyHtml);
$Header = $Doc->Find('h1');
$CountH1 = count($Header);
if ($CountH1 == 0) {
$this->SetData('Headline', Gdn_Format::Text($Page->Title));
} elseif ($CountH1 == 1) {
$this->SetData('Headline', $Header->Text());
$Header->Remove();
$this->ContentBodyHtml = $Doc->Html();
}
//
$this->AddModule('PageInfoModule');
$this->Render();
}
示例2: FormatBody
function FormatBody($Object)
{
Gdn::Controller()->FireEvent('BeforeCommentBody');
$Object->FormatBody = Gdn_Format::To($Object->Body, $Object->Format);
Gdn::Controller()->FireEvent('AfterCommentFormat');
return $Object->FormatBody;
}
示例3: Markdownify
/**
* Converts HTML to Markdown
*/
function Markdownify($Html)
{
$Html = Gdn_Format::To($Html, 'xHtml');
$Snoopy = Gdn::Factory('Snoopy');
$Vars = array('input' => $Html, 'keepHTML' => 1);
$Snoopy->Submit('http://milianw.de/projects/markdownify/demo.php', $Vars);
$Doc = PqDocument($Snoopy->results);
$Code = Pq('pre > code:eq(0)')->Text();
$Result = $Code;
return $Result;
}
示例4: Markdownify
/**
* Converts HTML to Markdown
*/
function Markdownify($Html)
{
if (function_exists('Debug') && Debug()) {
trigger_error(sprintf('%s is deprecated, use HtmlToMarkdown() instead.', __FUNCTION__), E_USER_DEPRECATED);
}
$Html = Gdn_Format::To($Html, 'xHtml');
$Snoopy = Gdn::Factory('Snoopy');
$Vars = array('input' => $Html, 'keepHTML' => 1);
$Snoopy->Submit('http://milianw.de/projects/markdownify/demo.php', $Vars);
$Doc = PqDocument($Snoopy->results);
$Code = Pq('pre > code:eq(0)')->Text();
$Result = $Code;
return $Result;
}
示例5: Gdn_Form_BeforeBodyBox_Handler
/**
*
* @param Gdn_Form $Sender
*/
public function Gdn_Form_BeforeBodyBox_Handler($Sender, $Args)
{
$this->_AddCLEditor(Gdn::Controller());
$Format = $Sender->GetValue('Format');
if ($Format) {
$Formatter = Gdn::Factory($Format . 'Formatter');
if ($Formatter && method_exists($Formatter, 'FormatForWysiwyg')) {
$Body = $Formatter->FormatForWysiwyg($Sender->GetValue('Body'));
$Sender->SetValue('Body', $Body);
} elseif (!in_array($Format, array('Html', 'Wysiwyg'))) {
$Sender->SetValue('Body', Gdn_Format::To($Sender->GetValue('Body'), $Format));
}
}
$Sender->SetValue('Format', 'Wysiwyg');
}
示例6: AttachFormattingBar
/**
* Adds the formatting bar to the form used by the Controller.
*
* @param Gdn_Controller $Sender Sending Controller instance.
*/
private function AttachFormattingBar(Gdn_Controller $Sender)
{
$this->_AddWysihtml5($Sender);
$Form = $Sender->Form;
$Format = $Form->GetValue('Format');
if ($Format) {
$Formatter = Gdn::Factory($Format . 'Formatter');
if ($Formatter && method_exists($Formatter, 'FormatForWysiwyg')) {
$Body = $Formatter->FormatForWysiwyg($Form->GetValue('Body'));
$Form->SetValue('Body', $Body);
} elseif (!in_array($Format, array('Html', 'Wysiwyg'))) {
$Form->SetValue('Body', Gdn_Format::To($Form->GetValue('Body'), $Format));
}
}
$Form->SetValue('Format', 'Wysiwyg');
echo $Sender->FetchView($this->GetView('toolbar_view.php'));
}
示例7: Update
public function Update($Reference = '', $PostBackKey = '')
{
$this->Permission('Candy.Chunks.Edit');
$Content = False;
$Session = Gdn::Session();
$this->AddJsFile('jquery.textpandable.js');
$this->AddJsFile('editform.js');
$this->Form->SetModel($this->ChunkModel);
if ($Reference != '') {
$Content = $this->ChunkModel->GetID($Reference);
if ($Content) {
$this->Form->AddHidden('ChunkID', $Content->ChunkID);
$this->Editing = True;
$this->Form->SetData($Content);
}
}
$IsFormPostBack = $this->Form->AuthenticatedPostBack();
$PostAuthenticatedByKey = $Session->ValidateTransientKey($PostBackKey) && $this->Form->IsPostBack();
if ($IsFormPostBack || $PostAuthenticatedByKey) {
if ($PostAuthenticatedByKey) {
// AJAX, set form values.
$this->Form->SetFormValue('ChunkID', $Content->ChunkID);
$this->Form->SetFormValue('Body', GetPostValue('Body'));
}
$SavedID = $this->Form->Save($Content);
if ($SavedID) {
$Message = T('Saved');
$this->InformMessage($Message, array('Sprite' => 'Check', 'CssClass' => 'Dismissable AutoDismiss'));
if ($this->DeliveryType() == DELIVERY_TYPE_BOOL) {
//$this->SetData('Content', $Content);
//$this->SetData('NewBody', Gdn_Format::To($this->Form->GetFormValue('Body'), $Content->Format));
$this->SetJson('NewBody', Gdn_Format::To($this->Form->GetFormValue('Body'), $Content->Format));
}
}
} else {
$this->SetData('Content', $Content);
$this->Form->SetData($Content);
}
$this->Title(ConcatSep(' - ', T('Chunk'), GetValue('Name', $Content)));
$this->Render();
}
示例8: FormatMentions
/**
* replaces /library/core/class.format.php function Mention
* code is as close to original function (taken from 2.0.18.9) as possible
*/
public function FormatMentions($Mixed)
{
if (!is_string($Mixed)) {
return Gdn_Format::To($Mixed, 'Mentions');
}
// Handle @mentions.
if (C('Garden.Format.Mentions')) {
// without spaces
$StrippedValidationRegex = '[' . str_replace(' ', '', str_replace('\\s', '', C('Garden.User.ValidationRegex'))) . ']' . C('Garden.User.ValidationLength', '{3,20}');
$Mixed = preg_replace('/(^|[\\s,\\.>])@(' . $StrippedValidationRegex . ')\\b/iu', '\\1' . Anchor('@\\2', '/profile/\\2'), $Mixed);
// with spaces
$Mixed = preg_replace('/(^|[\\s,\\.>])@' . C('Plugins.MentionsPlus.MentionStart', '"') . '(' . ValidateUsernameRegex() . ')' . C('Plugins.MentionsPlus.MentionStop', '"') . '/iu', '\\1' . Anchor('@' . C('Plugins.MentionsPlus.MentionStart', '"') . '\\2' . C('Plugins.MentionsPlus.MentionStop', '"'), '/profile/\\2'), $Mixed);
}
// Handle #hashtag searches
if (C('Garden.Format.Hashtags')) {
$Mixed = preg_replace('/(^|[\\s,\\.>])\\#([\\w\\-]+)(?=[\\s,\\.!?]|$)/iu', '\\1' . Anchor('#\\2', '/search?Search=%23\\2&Mode=like') . '\\3', $Mixed);
}
// Handle "/me does x" action statements
if (C('Garden.Format.MeActions')) {
$Mixed = preg_replace('/(^|[\\n])(\\' . C('Plugins.MentionsPlus.MeActionCode', '/me') . ')(\\s[^(\\n)]+)/iu', '\\1' . Wrap(Wrap('\\2', 'span', array('class' => 'MeActionName')) . '\\3', 'span', array('class' => 'AuthorAction')), $Mixed);
}
return $Mixed;
}
示例9: WriteReply
public static function WriteReply(&$Sender, &$Session)
{
?>
<li class="Reply" id="Comment_<?php
echo $Sender->CurrentReply->CommentID;
?>
">
<?php
// Delete comment
if ($Session->CheckPermission('Vanilla.Comments.Delete', $Sender->Discussion->CategoryID)) {
echo Anchor(T('Delete'), 'vanilla/discussion/deletecomment/' . $Sender->CurrentReply->CommentID . '/' . $Session->TransientKey(), 'DeleteReply');
}
?>
<ul class="Info<?php
echo $Sender->CurrentReply->InsertUserID == $Session->UserID ? ' Author' : '';
?>
">
<li class="Author"><?php
$Author = UserBuilder($Sender->CurrentReply, 'Insert');
echo UserPhoto($Author);
echo UserAnchor($Author);
?>
</li>
<li class="Created"><?php
echo Gdn_Format::Date($Sender->CurrentReply->DateInserted);
?>
</li>
<li class="Permalink"><?php
echo Anchor(T('Permalink'), '/discussion/comment/' . (isset($Sender->CurrentComment) ? $Sender->CurrentComment->CommentID : $Sender->ReplyCommentID) . '/#Comment_' . $Sender->CurrentReply->CommentID, T('Permalink'));
?>
</li>
</ul>
<div class="Body"><?php
echo Gdn_Format::To($Sender->CurrentReply->Body, $Sender->CurrentReply->Format);
?>
</div>
</li>
<?php
}
示例10: foreach
<?php
foreach ($this->Data('Conversations') as $Row) {
?>
<li id="Conversation_<?php
echo $Row['ConversationID'];
?>
" class="Item">
<?php
$JumpToItem = $Row['CountMessages'] - $Row['CountNewMessages'];
$Url = "/messages/{$Row['ConversationID']}/#Item_{$JumpToItem}";
if ($SubjectsVisible && $Row['Subject']) {
$Message = htmlspecialchars($Row['Title']);
} elseif ($Row['Format'] == 'Text') {
$Message = SliceString(Gdn_Format::To($Row['LastMessage'], $Conversation['Format']), 100);
} else {
$Message = SliceString(Gdn_Format::Text(Gdn_Format::To($Row['LastMessage'], $Row['Format']), FALSE), 100);
}
if (StringIsNullOrEmpty(trim($Message))) {
$Message = T('Blank Message');
}
echo Anchor($Message, $Url, 'ConversationLink');
?>
<div class="Meta">
<span class="MItem Participants">
<?php
$First = TRUE;
foreach ($Row['Participants'] as $User) {
if ($First) {
$First = FALSE;
} else {
echo ', ';
示例11: drawSignature
protected function drawSignature($Sender)
{
if ($this->hide()) {
return;
}
if (isset($Sender->EventArguments['Discussion'])) {
$Data = $Sender->EventArguments['Discussion'];
}
if (isset($Sender->EventArguments['Comment'])) {
$Data = $Sender->EventArguments['Comment'];
}
$SourceUserID = GetValue('InsertUserID', $Data);
$User = Gdn::UserModel()->GetID($SourceUserID, DATASET_TYPE_ARRAY);
if (GetValue('HideSignature', $User, FALSE)) {
return;
}
$Signature = $this->Signatures($Sender, $SourceUserID);
if (is_array($Signature)) {
list($Signature, $SigFormat) = $Signature;
} else {
$SigFormat = C('Garden.InputFormatter');
}
if (!$SigFormat) {
$SigFormat = C('Garden.InputFormatter');
}
$this->EventArguments = array('UserID' => $SourceUserID, 'Signature' => &$Signature);
$this->FireEvent('BeforeDrawSignature');
$SigClasses = '';
if (!is_null($Signature)) {
$HideImages = $this->UserPreferences('Plugin.Signatures.HideImages', FALSE);
if ($HideImages) {
$SigClasses .= 'HideImages ';
}
// Don't show empty sigs
if ($Signature == '') {
return;
}
// If embeds were disabled from the dashboard, temporarily set the
// universal config to make sure no URLs are turned into embeds.
if (!C('Plugins.Signatures.AllowEmbeds', true)) {
$originalEnableUrlEmbeds = C('Garden.Format.DisableUrlEmbeds', false);
SaveToConfig(array('Garden.Format.DisableUrlEmbeds' => true), null, array('Save' => false));
}
$UserSignature = Gdn_Format::To($Signature, $SigFormat) . "<!-- {$SigFormat} -->";
// Restore original config.
if (!C('Plugins.Signatures.AllowEmbeds', true)) {
SaveToConfig(array('Garden.Format.DisableUrlEmbeds' => $originalEnableUrlEmbeds), null, array('Save' => false));
}
$this->EventArguments = array('UserID' => $SourceUserID, 'String' => &$UserSignature);
$this->FireEvent('FilterContent');
if ($UserSignature) {
echo "<div class=\"Signature UserSignature {$SigClasses}\">{$UserSignature}</div>";
}
}
}
示例12: WriteComment
/**
* $Object is either a Comment or the original Discussion.
*/
function WriteComment($Object, $Sender, $Session, $CurrentOffset)
{
$Author = UserBuilder($Object, 'Insert');
$Type = property_exists($Object, 'CommentID') ? 'Comment' : 'Discussion';
$Sender->EventArguments['Object'] = $Object;
$Sender->EventArguments['Type'] = $Type;
$Sender->EventArguments['Author'] = $Author;
$CssClass = 'Item Comment';
if ($Type == 'Comment') {
$Sender->EventArguments['Comment'] = $Object;
$Id = 'Comment_' . $Object->CommentID;
$Permalink = '/discussion/comment/' . $Object->CommentID . '/#Comment_' . $Object->CommentID;
} else {
$Sender->EventArguments['Discussion'] = $Object;
$CssClass .= ' FirstComment';
$Id = 'Discussion_' . $Object->DiscussionID;
$Permalink = '/discussion/' . $Object->DiscussionID . '/' . Gdn_Format::Url($Object->Name) . '/p1';
}
$Sender->Options = '';
$CssClass .= $Object->InsertUserID == $Session->UserID ? ' Mine' : '';
$Sender->FireEvent('BeforeCommentDisplay');
?>
<li class="<?php
echo $CssClass;
?>
" id="<?php
echo $Id;
?>
">
<div class="Comment">
<div class="Meta">
<?php
$Sender->FireEvent('BeforeCommentMeta');
?>
<span class="Author">
<?php
echo UserPhoto($Author);
echo UserAnchor($Author);
?>
</span>
<span class="DateCreated">
<?php
echo Gdn_Format::Date($Object->DateInserted);
?>
</span>
<span class="Permalink">
<?php
echo Anchor(T('Permalink'), $Permalink, 'Permalink', array('name' => 'Item_' . ($CurrentOffset + 1), 'rel' => 'nofollow'));
?>
</span>
<?php
WriteOptionList($Object, $Sender, $Session);
?>
<?php
$Sender->FireEvent('AfterCommentMeta');
?>
</div>
<div class="Message">
<?php
$Sender->FireEvent('BeforeCommentBody');
?>
<p><?php
echo Gdn_Format::To($Object->Body, $Object->Format);
?>
</p>
</div>
<?php
$Sender->FireEvent('AfterCommentBody');
?>
</div>
</li>
<?php
$Sender->FireEvent('AfterComment');
}
示例13: RefetchPageInfo
/**
* Re-fetch a discussion's content based on its foreign url.
* @param type $DiscussionID
*/
public function RefetchPageInfo($DiscussionID)
{
// Make sure we are posting back.
if (!$this->Request->IsPostBack()) {
throw PermissionException('Javascript');
}
// Grab the discussion.
$Discussion = $this->DiscussionModel->GetID($DiscussionID);
if (!$Discussion) {
throw NotFoundException('Discussion');
}
// Make sure the user has permission to edit this discussion.
$this->Permission('Vanilla.Discussions.Edit', TRUE, 'Category', $Discussion->PermissionCategoryID);
$ForeignUrl = GetValueR('Attributes.ForeignUrl', $Discussion);
if (!$ForeignUrl) {
throw new Gdn_UserException(T("This discussion isn't associated with a url."));
}
$Stub = $this->DiscussionModel->FetchPageInfo($ForeignUrl, TRUE);
// Save the stub.
$this->DiscussionModel->SetField($DiscussionID, (array) $Stub);
// Send some of the stuff back.
if (isset($Stub['Name'])) {
$this->JsonTarget('.PageTitle h1', Gdn_Format::Text($Stub['Name']));
}
if (isset($Stub['Body'])) {
$this->JsonTarget("#Discussion_{$DiscussionID} .Message", Gdn_Format::To($Stub['Body'], $Stub['Format']));
}
$this->InformMessage('The page was successfully fetched.');
$this->Render('Blank', 'Utility', 'Dashboard');
}
示例14: defined
<?php
defined('APPLICATION') or exit;
$Session = Gdn::Session();
// Format page body.
$PageBody = $this->Page->Body;
if ($this->Page->Format === 'RawHtmlLineBreaks') {
$PageBody = preg_replace("/(\r\n)|(\r)|(\n)/", "<br />", $PageBody);
$PageBody = FixNl2Br($PageBody);
} else {
if ($this->Page->Format !== 'RawHtml') {
$PageBody = Gdn_Format::To($PageBody, $this->Page->Format);
}
}
?>
<div id="Page_<?php
echo $this->Page->PageID;
?>
" class="PageContent Page-<?php
echo $this->Page->UrlCode;
?>
">
<?php
$this->FireEvent('BeforePageOptions');
?>
<?php
if ($Session->CheckPermission('Garden.Settings.Manage')) {
?>
<div class="Options">
<span class="ToggleFlyout OptionsMenu">
<span class="OptionsTitle" title="<?php
示例15: RssHtml
/**
* Format some text in a way suitable for passing into an rss/atom feed.
* @since 2.1
* @param string $Text The text to format.
* @param string $Format The current format of the text.
* @return string
*/
public static function RssHtml($Text, $Format = 'Html')
{
if (!in_array($Text, array('Html', 'Raw'))) {
$Text = Gdn_Format::To($Text, $Format);
}
if (function_exists('FormatRssHtmlCustom')) {
return FormatRssHtmlCustom($Text);
} else {
return Gdn_Format::Html($Text);
}
}