Ejemplo n.º 1
0
 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();
 }
Ejemplo n.º 2
0
 function FormatBody($Object)
 {
     Gdn::Controller()->FireEvent('BeforeCommentBody');
     $Object->FormatBody = Gdn_Format::To($Object->Body, $Object->Format);
     Gdn::Controller()->FireEvent('AfterCommentFormat');
     return $Object->FormatBody;
 }
Ejemplo n.º 3
0
 /**
  * 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;
 }
 /**
  * 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;
 }
Ejemplo n.º 5
0
 /**
  *
  * @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');
 }
Ejemplo n.º 6
0
 /**
  * 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'));
 }
Ejemplo n.º 7
0
 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();
 }
 /**
  *  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;
 }
Ejemplo n.º 9
0
    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 
    }
Ejemplo n.º 10
0
      <?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 ', ';
Ejemplo n.º 11
0
 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>";
         }
     }
 }
Ejemplo n.º 12
0
/**
 * $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');
}
 /**
  * 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');
 }
Ejemplo n.º 14
0
<?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 
Ejemplo n.º 15
0
 /**
  * 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);
     }
 }
Ejemplo n.º 16
0
function WritePromotedContent($Content, $Sender)
{
    static $UserPhotoFirst = NULL;
    if ($UserPhotoFirst === NULL) {
        $UserPhotoFirst = C('Vanilla.Comment.UserPhotoFirst', TRUE);
    }
    $ContentType = GetValue('ItemType', $Content);
    $ContentID = GetValue("{$ContentType}ID", $Content);
    $Author = GetValue('Author', $Content);
    switch (strtolower($ContentType)) {
        case 'comment':
            $ContentURL = CommentUrl($Content);
            break;
        case 'discussion':
            $ContentURL = DiscussionUrl($Content);
            break;
    }
    ?>
   <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(GetValue('Title', $Author)), 'span', array('class' => 'MItem AuthorTitle'));
    echo ' ' . WrapIf(htmlspecialchars(GetValue('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'), $Permalink, 'Permalink', array('rel' => 'nofollow'));
    ?>
         </span>
         <?php 
    // Include source if one was set
    if ($Source = GetValue('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($Content['Name'], FALSE), $ContentURL, 'DiscussionLink');
    ?>
</div>
      <div class="Body"><?php 
    echo Anchor(strip_tags(Gdn_Format::To($Content['Body'], $Content['Format'])), $ContentURL, 'BodyLink');
    ?>
</div>
   </div>
<?php 
}
Ejemplo n.º 17
0
<?php

if (!defined('APPLICATION')) {
    exit;
}
$this->FireEvent('BeforeCommentPreviewFormat');
$this->Comment->Body = Gdn_Format::To($this->Comment->Body, C('Garden.InputFormatter'));
$this->FireEvent('AfterCommentPreviewFormat');
?>
<div class="Preview">
   <div class="Message"><?php 
echo $this->Comment->Body;
?>
</div>
</div>
Ejemplo n.º 18
0
         <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 = GetValue('Source', $Content)) {
        echo Wrap(sprintf(T('via %s'), T($Source . ' Source', $Source)), 'span', array('class' => 'MItem Source'));
    }
    ?>
      </div>
     </div>
     <div class="Item-BodyWrap">
       <div class="Item-Body">
         <div class="Message Expander">
          <?php 
    echo Gdn_Format::To($Content['Body'], $Content['Format']);
    ?>
         </div>
         <?php 
    if (C('Yaga.Reactions.Enabled') && Gdn::Session()->CheckPermission('Yaga.Reactions.View')) {
        RenderReactionRecord($ContentID, strtolower($ContentType));
    }
    ?>
       </div>
     </div>
   </li> <?php 
}
echo '</ul>';
echo $this->Pager->ToString();
Ejemplo n.º 19
0
 public function Search($Search, $Offset = 0, $Limit = 20)
 {
     // If there are no searches then return an empty array.
     if (trim($Search) == '') {
         return array();
     }
     // Figure out the exact search mode.
     if ($this->ForceSearchMode) {
         $SearchMode = $this->ForceSearchMode;
     } else {
         $SearchMode = strtolower(C('Garden.Search.Mode', 'matchboolean'));
     }
     if ($SearchMode == 'matchboolean') {
         if (strpos($Search, '+') !== FALSE || strpos($Search, '-') !== FALSE) {
             $SearchMode = 'boolean';
         } else {
             $SearchMode = 'match';
         }
     } else {
         $this->_SearchMode = $SearchMode;
     }
     if ($ForceDatabaseEngine = C('Database.ForceStorageEngine')) {
         if (strcasecmp($ForceDatabaseEngine, 'myisam') != 0) {
             $SearchMode = 'like';
         }
     }
     $this->_SearchMode = $SearchMode;
     $this->FireEvent('Search');
     if (count($this->_SearchSql) == 0) {
         return array();
     }
     // Perform the search by unioning all of the sql together.
     $Sql = $this->SQL->Select()->From('_TBL_ s')->OrderBy('s.DateInserted', 'desc')->Limit($Limit, $Offset)->GetSelect();
     $Sql = str_replace($this->Database->DatabasePrefix . '_TBL_', "(\n" . implode("\nunion all\n", $this->_SearchSql) . "\n)", $Sql);
     $this->EventArguments['Search'] = $Search;
     $this->FireEvent('AfterBuildSearchQuery');
     if ($this->_SearchMode == 'like') {
         $Search = '%' . $Search . '%';
     }
     foreach ($this->_Parameters as $Key => $Value) {
         $this->_Parameters[$Key] = $Search;
     }
     $Parameters = $this->_Parameters;
     $this->Reset();
     $this->SQL->Reset();
     $Result = $this->Database->Query($Sql, $Parameters)->ResultArray();
     foreach ($Result as $Key => $Value) {
         if (isset($Value['Summary'])) {
             $Value['Summary'] = Gdn_Format::Text(Gdn_Format::To($Value['Summary'], $Value['Format']));
             $Result[$Key] = $Value;
         }
     }
     return $Result;
 }
Ejemplo n.º 20
0
 /**
  * Record advanced notifications for users.
  * 
  * @param ActivityModel $ActivityModel
  * @param array $Discussion
  * @param int $CommentID
  * @param array $NotifiedUsers 
  */
 public function RecordAdvancedNotications($ActivityModel, $Discussion, $Comment, &$NotifiedUsers)
 {
     // Grab all of the users that need to be notified.
     $Data = $this->SQL->GetWhere('UserMeta', array('Name' => 'Preferences.Email.NewDiscussion'))->ResultArray();
     // Grab all of their follow/unfollow preferences.
     $UserIDs = ConsolidateArrayValuesByKey($Data, 'UserID');
     $CategoryID = GetValue('CategoryID', $Discussion);
     $UserPrefs = $this->SQL->Select('*')->From('UserCategory')->Where('CategoryID', $CategoryID)->WhereIn('UserID', $UserIDs)->Get()->ResultArray();
     $UserPrefs = Gdn_DataSet::Index($UserPrefs, 'UserID');
     $CommentID = $Comment['CommentID'];
     foreach ($UserIDs as $UserID) {
         //         if ($UserID == $Comment['InsertUserID'])
         //            continue;
         if (in_array($UserID, $NotifiedUsers)) {
             continue;
         }
         if (array_key_exists($UserID, $UserPrefs) && $UserPrefs[$UserID]['Unfollow']) {
             continue;
         }
         $ActivityID = AddActivity($Comment['InsertUserID'], 'NewComment', Gdn_Format::Text(Gdn_Format::To($Comment['Body'], $Comment['Format'])), $UserID, "/discussion/comment/{$CommentID}#Comment_{$CommentID}", TRUE);
         //         $ActivityModel->QueueNotification($ActivityID);
         $NotifiedUsers[] = $UserID;
     }
 }
Ejemplo n.º 21
0
}
foreach ($this->CommentData->Result() as $Comment) {
    $Permalink = '/discussion/comment/' . $Comment->CommentID . '/#Comment_' . $Comment->CommentID;
    $User = UserBuilder($Comment, 'Insert');
    $this->EventArguments['User'] = $User;
    ?>
<li class="Item">
	<?php 
    $this->FireEvent('BeforeItemContent');
    ?>
	<div class="ItemContent">
		<?php 
    echo Anchor(Gdn_Format::Text($Comment->DiscussionName), $Permalink, 'Title');
    ?>
		<div class="Excerpt"><?php 
    echo Anchor(SliceString(Gdn_Format::Text(Gdn_Format::To($Comment->Body, $Comment->Format), FALSE), 250), $Permalink);
    ?>
</div>
		<div class="Meta">
			<span><?php 
    printf(T('Comment by %s'), UserAnchor($User));
    ?>
</span>
			<span><?php 
    echo Gdn_Format::Date($Comment->DateInserted);
    ?>
</span>
			<span><?php 
    echo Anchor(T('permalink'), $Permalink);
    ?>
</span>
Ejemplo n.º 22
0
function WriteActivityComment($Comment, &$Sender, &$Session)
{
    $Author = UserBuilder($Comment, 'Insert');
    $PhotoAnchor = UserPhoto($Author, 'Photo');
    $CssClass = 'Item ActivityComment ActivityComment';
    if ($PhotoAnchor != '') {
        $CssClass .= ' HasPhoto';
    }
    ?>
<li id="ActivityComment_<?php 
    echo $Comment['ActivityCommentID'];
    ?>
" class="<?php 
    echo $CssClass;
    ?>
">
   <?php 
    if ($PhotoAnchor != '') {
        ?>
   <div class="Author Photo"><?php 
        echo $PhotoAnchor;
        ?>
</div>
   <?php 
    }
    ?>
   <div class="ItemContent ActivityComment">
      <?php 
    echo UserAnchor($Author, 'Title Name');
    ?>
      <div class="Excerpt"><?php 
    echo Gdn_Format::To($Comment['Body'], $Comment['Format']);
    ?>
</div>
      <div class="Meta">
         <span class="DateCreated"><?php 
    echo Gdn_Format::Date($Comment['DateInserted'], 'html');
    ?>
</span>
         <?php 
    if ($Session->UserID == $Comment['InsertUserID'] || $Session->CheckPermission('Garden.Activity.Delete')) {
        echo Anchor(T('Delete'), "dashboard/activity/deletecomment?id={$Comment['ActivityCommentID']}&tk=" . $Session->TransientKey() . '&target=' . urlencode(Gdn_Url::Request()), 'DeleteComment');
    }
    ?>
      </div>
   </div>
</li>
<?php 
}
Ejemplo n.º 23
0
/**
 * $Object is either a Comment or the original Discussion.
 */
function WriteComment($Object, $Sender, $Session, $CurrentOffset) {
   $Alt = ($CurrentOffset % 2) != 0;

   $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';
   $Permalink = GetValue('Url', $Object, FALSE);

   if ($Type == 'Comment') {
      $Sender->EventArguments['Comment'] = $Object;   
      $Id = 'Comment_'.$Object->CommentID;
      if ($Permalink === FALSE)
         $Permalink = '/discussion/comment/'.$Object->CommentID.'/#Comment_'.$Object->CommentID;
   } else {
      $Sender->EventArguments['Discussion'] = $Object;   
      $CssClass .= ' FirstComment';
      $Id = 'Discussion_'.$Object->DiscussionID;
      if ($Permalink === FALSE)
         $Permalink = '/discussion/'.$Object->DiscussionID.'/'.Gdn_Format::Url($Object->Name).'/p1';
   }
   $Sender->EventArguments['CssClass'] = &$CssClass;
   $Sender->Options = '';
   $CssClass .= $Object->InsertUserID == $Session->UserID ? ' Mine' : '';

   if ($Alt)
      $CssClass .= ' Alt';
   $Alt = !$Alt;
	
	if (!property_exists($Sender, 'CanEditComments'))
		$Sender->CanEditComments = $Session->CheckPermission('Vanilla.Comments.Edit', TRUE, 'Category', 'any') && C('Vanilla.AdminCheckboxes.Use');
		
   $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 Anchor(Gdn_Format::Date($Object->DateInserted), $Permalink, 'Permalink', array('name' => 'Item_'.($CurrentOffset+1), 'rel' => 'nofollow'));
            ?>
         </span>
         <?php
			WriteOptionList($Object, $Sender, $Session);
			if ($Type == 'Comment' && $Sender->CanEditComments) {
				if (!property_exists($Sender, 'CheckedComments'))
					$Sender->CheckedComments = $Session->GetAttribute('CheckedComments', array());
					
				$ItemSelected = InSubArray($Id, $Sender->CheckedComments);
				echo '<div class="Administration"><input type="checkbox" name="'.$Type.'ID[]" value="'.$Id.'"'.($ItemSelected?' checked="checked"':'').' /></div>';
			}
			?>
         <div class="CommentInfo">
            <?php $Sender->FireEvent('CommentInfo'); ?>
         </div>
         <?php $Sender->FireEvent('AfterCommentMeta'); ?>
      </div>
      <div class="Message">
			<?php 
            $Sender->FireEvent('BeforeCommentBody'); 
			   $Object->FormatBody = Gdn_Format::To($Object->Body, $Object->Format);
			   $Sender->FireEvent('AfterCommentFormat');
			   $Object = $Sender->EventArguments['Object'];
			   echo $Object->FormatBody;
			?>
		</div>
      <?php $Sender->FireEvent('AfterCommentBody'); ?>
   </div>
</li>
<?php
	$Sender->FireEvent('AfterComment');
}
<?php 
foreach ($this->DiscussionData->Result() as $Discussion) {
    ?>
   <item>
      <title><?php 
    echo Gdn_Format::Text($Discussion->Name);
    ?>
</title>
      <link><?php 
    echo htmlspecialchars(Url('/discussion/' . $Discussion->DiscussionID . '/' . Gdn_Format::Url($Discussion->Name), TRUE));
    ?>
</link>
      <pubDate><?php 
    echo date(DATE_RSS, Gdn_Format::ToTimeStamp($Discussion->DateInserted));
    ?>
</pubDate>
      <dc:creator><?php 
    echo Gdn_Format::Text($Discussion->FirstName);
    ?>
</dc:creator>
      <guid isPermaLink="false"><?php 
    echo $Discussion->DiscussionID . '@' . Url('/discussions');
    ?>
</guid>
      <description><![CDATA[<?php 
    echo Gdn_Format::To($Discussion->Body, $Discussion->Format);
    ?>
]]></description>
   </item>
<?php 
}
Ejemplo n.º 25
0
	/**
	 * Format the resultset with the given method.
	 *
	 * @param string $FormatMethod The method to use with Gdn_Format::To().
	 * @return Gdn_Dataset $this pointer for chaining.
	 */
	public function Format($FormatMethod) {
		$Result = &$this->Result();
		foreach($Result as $Index => $Value) {
			$Result[$Index] = Gdn_Format::To($Value, $FormatMethod);
		}
		return $this;
	}
Ejemplo n.º 26
0
$Alt = FALSE;
$SubjectsVisible = C('Conversations.Subjects.Visible');

foreach ($this->ConversationData->Result() as $Conversation) {
   $Alt = $Alt == TRUE ? FALSE : TRUE;
   $LastAuthor = UserBuilder($Conversation, 'LastMessage');
   $LastPhoto = UserPhoto($LastAuthor, 'Photo');
   $CssClass = 'Item';
   $CssClass .= $Alt ? ' Alt' : '';
   $CssClass .= $Conversation->CountNewMessages > 0 ? ' New' : '';
   $CssClass .= $LastPhoto != '' ? ' HasPhoto' : '';
   $JumpToItem = $Conversation->CountMessages - $Conversation->CountNewMessages;
   if ($Conversation->Format == 'Text')
      $Message = nl2br(SliceString(Gdn_Format::To($Conversation->LastMessage, $Conversation->Format), 100));
   else
      $Message = nl2br(SliceString(Gdn_Format::Text(Gdn_Format::To($Conversation->LastMessage, $Conversation->Format), FALSE), 100));

   if (StringIsNullOrEmpty(trim($Message)))
      $Message = T('Blank Message');


   $this->EventArguments['Conversation'] = $Conversation;
?>
<li class="<?php echo $CssClass; ?>">
   <?php
   $Names = '';
   $PhotoUser = NULL;
   foreach ($Conversation->Participants as $User) {
      if (GetValue('UserID', $User) == Gdn::Session()->UserID)
         continue;
      $Names = ConcatSep(', ', $Names, GetValue('Name', $User));
Ejemplo n.º 27
0
 public function Search($Search, $Offset = 0, $Limit = 20)
 {
     $AllSettings = SphinxFactory::BuildSettings();
     $Settings = $AllSettings->GetAllSettings();
     // if (($Settings['Status']->SearchdRunning == 1) && ($Settings['Status']->EnableSphinxSearch == 1))
     if (true) {
         // Force this to be true while the sphinxsearch plugin is enabled!
         return FALSE;
     } else {
         // If there are no searches then return an empty array.
         if (trim($Search) == '') {
             return array();
         }
         // Figure out the exact search mode.
         if ($this->ForceSearchMode) {
             $SearchMode = $this->ForceSearchMode;
         } else {
             $SearchMode = strtolower(C('Garden.Search.Mode', 'matchboolean'));
         }
         if ($SearchMode == 'matchboolean') {
             if (strpos($Search, '+') !== FALSE || strpos($Search, '-') !== FALSE) {
                 $SearchMode = 'boolean';
             } else {
                 $SearchMode = 'match';
             }
         } else {
             $this->_SearchMode = $SearchMode;
         }
         $this->_SearchMode = $SearchMode;
         $this->FireEvent('Search');
         //print_r($this->_SearchSql);
         if (count($this->_SearchSql) == 0) {
             return array();
         }
         // Perform the search by unioning all of the sql together.
         $Sql = $this->SQL->Select()->From('_TBL_ s')->OrderBy('s.DateInserted', 'desc')->Limit($Limit, $Offset)->GetSelect();
         $Sql = str_replace($this->Database->DatabasePrefix . '_TBL_', "(\n" . implode("\nunion all\n", $this->_SearchSql) . "\n)", $Sql);
         $this->EventArguments['Search'] = $Search;
         $this->FireEvent('AfterBuildSearchQuery');
         if ($this->_SearchMode == 'like') {
             $Search = '%' . $Search . '%';
         }
         foreach ($this->_Parameters as $Key => $Value) {
             $this->_Parameters[$Key] = $Search;
         }
         $Result = $this->Database->Query($Sql, $this->_Parameters)->ResultArray();
         $this->Reset();
         $this->SQL->Reset();
         foreach ($Result as $Key => $Value) {
             if (isset($Value['Summary'])) {
                 $Value['Summary'] = Gdn_Format::Text(Gdn_Format::To($Value['Summary'], $Value['Format']));
                 $Result[$Key] = $Value;
             }
         }
         return $Result;
     }
 }
Ejemplo n.º 28
0
 function ValidateMinTextLength($Value, $Field, $Post)
 {
     if (isset($Post['Format'])) {
         $Value = Gdn_Format::To($Value, $Post['Format']);
     }
     $Value = html_entity_decode(trim(strip_tags($Value)));
     $MinLength = GetValue('MinLength', $Field, 0);
     if (function_exists('mb_strlen')) {
         $Diff = $MinLength - mb_strlen($Value, 'UTF-8');
     } else {
         $Diff = $MinLength - strlen($Value);
     }
     if ($Diff <= 0) {
         return TRUE;
     } else {
         return sprintf(T('ValidateMinLength'), T($Field->Name), $Diff);
     }
 }
Ejemplo n.º 29
0
 /**
  * Renders a chunk of text
  * 
  * @param mixed $Identify ChunckID.
  * @param mixed $Options type of chunk (Textarea [default], Text)
  * @return mixed $Result.
  */
 function Chunk($Identify, $Options = False)
 {
     static $ChunkModel;
     if (is_null($ChunkModel)) {
         $ChunkModel = new ChunkModel();
     }
     static $PermissionChunksEdit;
     if (is_null($PermissionChunksEdit)) {
         $PermissionChunksEdit = CheckPermission('Candy.Chunks.Edit');
     }
     $Data = $ChunkModel->GetID($Identify);
     if ($Data != False) {
         $String = Gdn_Format::To($Data->Body, $Data->Format);
         $Type = ArrayValueI('type', $Options, 'Textarea');
         $Class = ArrayValueI('class', $Options, '');
         if ($Type) {
             if ($PermissionChunksEdit) {
                 $Class .= ' Editable Editable' . $Type;
             }
             $String = Wrap($String, 'div', array('class' => trim($Class), 'id' => 'Chunk' . $Data->ChunkID));
         }
         return $String;
     }
 }
Ejemplo n.º 30
0
    echo $Message->MessageID;
    ?>
"<?php 
    echo $Class == '' ? '' : ' class="' . $Class . '"';
    ?>
>
   <div class="ConversationMessage">
      <div class="Meta">
         <span class="Author">
            <?php 
    echo UserPhoto($Author, 'Photo');
    echo UserAnchor($Author, 'Name');
    ?>
         </span>
         <span class="DateCreated"><?php 
    echo Gdn_Format::Date($Message->DateInserted);
    ?>
</span>
         <span class="ItemLink"><a name="Item_<?php 
    echo $CurrentOffset;
    ?>
" class="Item"></a></span>
      </div>
      <div class="Message"><?php 
    echo Gdn_Format::To($Message->Body, $Format);
    ?>
</div>
   </div>
</li>
<?php 
}