/**
  * List download stats.
  *
  * @param bool|false $Offset
  */
 public function index($Offset = false)
 {
     $this->permission('Garden.Settings.Manage');
     $this->addSideMenu('vstats');
     $this->addJsFile('jquery.gardenmorepager.js');
     $this->title('Vanilla Stats');
     $this->Form->Method = 'get';
     $Offset = is_numeric($Offset) ? $Offset : 0;
     $Limit = 19;
     $this->StatsData = array();
     $Offset--;
     $Year = date('Y');
     $Month = date('m');
     $BaseDate = Gdn_Format::toTimestamp($Year . '-' . str_pad($Month, 2, '0', STR_PAD_LEFT) . '-01 00:00:00');
     for ($i = $Offset; $i <= $Limit; ++$i) {
         $String = "-{$i} month";
         $this->StatsData[] = $this->_getStats(date("Y-m-d 00:00:00", strtotime($String, $BaseDate)));
     }
     $TotalRecords = count($this->StatsData);
     // Build a pager
     $PagerFactory = new Gdn_PagerFactory();
     $this->Pager = $PagerFactory->getPager('MorePager', $this);
     $this->Pager->MoreCode = 'More';
     $this->Pager->LessCode = 'Previous';
     $this->Pager->ClientID = 'Pager';
     $this->Pager->Wrapper = '<tr %1$s><td colspan="6">%2$s</td></tr>';
     $this->Pager->configure($Offset, $Limit, $TotalRecords, 'vstats/index/%1$s/');
     // Deliver json data if necessary
     if ($this->_DeliveryType != DELIVERY_TYPE_ALL) {
         $this->setJson('LessRow', $this->Pager->toString('less'));
         $this->setJson('MoreRow', $this->Pager->toString('more'));
     }
     $this->render();
 }
 /**
  * List all update checks.
  *
  * @param bool|false $Offset
  * @param string $SortField
  */
 public function index($Offset = false, $SortField = '')
 {
     $this->permission('Garden.Settings.Manage');
     $this->addSideMenu('updates');
     $this->addJsFile('jquery.gardenmorepager.js');
     $this->title('Remote Updates');
     $this->Form->Method = 'get';
     $Limit = 30;
     $SortField = $SortField == 'CountComments' ? 'c.CountComments' : 'c.DateInserted';
     // Input Validation
     $Offset = is_numeric($Offset) ? $Offset : 0;
     // What the actual model in my controller, guy?
     $this->UpdateData = Gdn::sql()->query("\n            select s.Location, s.RemoteIp, c.DateInserted, c.CountUsers, c.CountDiscussions, c.CountComments\n            from GDN_UpdateCheckSource s\n            join (select SourceID, max(UpdateCheckID) as UpdateCheckID from GDN_UpdateCheck group by SourceID) mc\n                on s.SourceID = mc.SourceID\n            join GDN_UpdateCheck c\n                on mc.UpdateCheckID = c.UpdateCheckID\n            order by {$SortField} desc\n            limit {$Offset}, {$Limit}");
     $TotalRecords = Gdn::sql()->select('SourceID', 'count', 'CountSources')->from('UpdateCheckSource')->get()->firstRow()->CountSources;
     // Build a pager
     $PagerFactory = new Gdn_PagerFactory();
     $this->Pager = $PagerFactory->getPager('MorePager', $this);
     $this->Pager->MoreCode = 'More';
     $this->Pager->LessCode = 'Previous';
     $this->Pager->ClientID = 'Pager';
     $this->Pager->Wrapper = '<tr %1$s><td colspan="6">%2$s</td></tr>';
     $this->Pager->configure($Offset, $Limit, $TotalRecords, 'updates/index/%1$s/' . urlencode($SortField));
     // Deliver json data if necessary
     if ($this->_DeliveryType != DELIVERY_TYPE_ALL) {
         $this->setJson('LessRow', $this->Pager->toString('less'));
         $this->setJson('MoreRow', $this->Pager->toString('more'));
     }
     $this->render();
 }
    /**
     * Alternate version of Index that uses the embed master view.
     *
     * @param int $DiscussionID Unique identifier, if discussion has been created.
     * @param string $DiscussionStub Deprecated.
     * @param int $Offset
     * @param int $Limit
     */
    public function embed($DiscussionID = '', $DiscussionStub = '', $Offset = '', $Limit = '')
    {
        $this->title(t('Comments'));
        // Add theme data
        $this->Theme = c('Garden.CommentsTheme', $this->Theme);
        Gdn_Theme::section('Comments');
        // Force view options
        $this->MasterView = 'empty';
        $this->CanEditComments = false;
        // Don't show the comment checkboxes on the embed comments page
        // Add some css to help with the transparent bg on embedded comments
        if ($this->Head) {
            $this->Head->addString('<style type="text/css">
body { background: transparent !important; }
</style>');
        }
        // Javascript files & options
        $this->addJsFile('jquery.gardenmorepager.js');
        $this->addJsFile('jquery.autosize.min.js');
        $this->addJsFile('discussion.js');
        $this->removeJsFile('autosave.js');
        $this->addDefinition('DoInform', '0');
        // Suppress inform messages on embedded page.
        $this->addDefinition('SelfUrl', Gdn::request()->PathAndQuery());
        $this->addDefinition('Embedded', true);
        // Define incoming variables (prefer querystring parameters over method parameters)
        $DiscussionID = is_numeric($DiscussionID) && $DiscussionID > 0 ? $DiscussionID : 0;
        $DiscussionID = getIncomingValue('vanilla_discussion_id', $DiscussionID);
        $Offset = getIncomingValue('Offset', $Offset);
        $Limit = getIncomingValue('Limit', $Limit);
        $vanilla_identifier = getIncomingValue('vanilla_identifier', '');
        // Only allow vanilla identifiers of 32 chars or less - md5 if larger
        if (strlen($vanilla_identifier) > 32) {
            $vanilla_identifier = md5($vanilla_identifier);
        }
        $vanilla_type = getIncomingValue('vanilla_type', 'page');
        $vanilla_url = getIncomingValue('vanilla_url', '');
        $vanilla_category_id = getIncomingValue('vanilla_category_id', '');
        $ForeignSource = array('vanilla_identifier' => $vanilla_identifier, 'vanilla_type' => $vanilla_type, 'vanilla_url' => $vanilla_url, 'vanilla_category_id' => $vanilla_category_id);
        $this->setData('ForeignSource', $ForeignSource);
        // Set comment sorting
        $SortComments = c('Garden.Embed.SortComments') == 'desc' ? 'desc' : 'asc';
        $this->setData('SortComments', $SortComments);
        // Retrieve the discussion record
        $Discussion = false;
        if ($DiscussionID > 0) {
            $Discussion = $this->DiscussionModel->getID($DiscussionID);
        } elseif ($vanilla_identifier != '' && $vanilla_type != '') {
            $Discussion = $this->DiscussionModel->GetForeignID($vanilla_identifier, $vanilla_type);
        }
        // Set discussion data if we have one for this page
        if ($Discussion) {
            // Allow Vanilla.Comments.View to be defined to limit access to embedded comments only.
            // Otherwise, go with normal discussion view permissions. Either will do.
            $this->permission(array('Vanilla.Discussions.View', 'Vanilla.Comments.View'), false, 'Category', $Discussion->PermissionCategoryID);
            $this->setData('Discussion', $Discussion, true);
            $this->setData('DiscussionID', $Discussion->DiscussionID, true);
            $this->title($Discussion->Name);
            // Actual number of comments, excluding the discussion itself
            $ActualResponses = $Discussion->CountComments;
            // Define the query offset & limit
            if (!is_numeric($Limit) || $Limit < 0) {
                $Limit = c('Garden.Embed.CommentsPerPage', 30);
            }
            $OffsetProvided = $Offset != '';
            list($Offset, $Limit) = offsetLimit($Offset, $Limit);
            $this->Offset = $Offset;
            if (c('Vanilla.Comments.AutoOffset')) {
                if ($ActualResponses <= $Limit) {
                    $this->Offset = 0;
                }
                if ($this->Offset == $ActualResponses) {
                    $this->Offset -= $Limit;
                }
            } elseif ($this->Offset == '') {
                $this->Offset = 0;
            }
            if ($this->Offset < 0) {
                $this->Offset = 0;
            }
            // Set the canonical url to have the proper page title.
            $this->canonicalUrl(discussionUrl($Discussion, pageNumber($this->Offset, $Limit)));
            // Load the comments.
            $CurrentOrderBy = $this->CommentModel->orderBy();
            if (stringBeginsWith(GetValueR('0.0', $CurrentOrderBy), 'c.DateInserted')) {
                $this->CommentModel->orderBy('c.DateInserted ' . $SortComments);
                // allow custom sort
            }
            $this->setData('Comments', $this->CommentModel->get($Discussion->DiscussionID, $Limit, $this->Offset), true);
            if (count($this->CommentModel->where()) > 0) {
                $ActualResponses = false;
            }
            $this->setData('_Count', $ActualResponses);
            // Build a pager
            $PagerFactory = new Gdn_PagerFactory();
            $this->EventArguments['PagerType'] = 'MorePager';
            $this->fireEvent('BeforeBuildPager');
            $this->Pager = $PagerFactory->getPager($this->EventArguments['PagerType'], $this);
            $this->Pager->ClientID = 'Pager';
            $this->Pager->MoreCode = 'More Comments';
            $this->Pager->configure($this->Offset, $Limit, $ActualResponses, 'discussion/embed/' . $Discussion->DiscussionID . '/' . Gdn_Format::url($Discussion->Name) . '/%1$s');
            $this->Pager->CurrentRecords = $this->Comments->numRows();
            $this->fireEvent('AfterBuildPager');
        }
        // Define the form for the comment input
        $this->Form = Gdn::Factory('Form', 'Comment');
        $this->Form->Action = url('/post/comment/');
        $this->Form->addHidden('CommentID', '');
        $this->Form->addHidden('Embedded', 'true');
        // Tell the post controller that this is an embedded page (in case there are custom views it needs to pick up from a theme).
        $this->Form->addHidden('DisplayNewCommentOnly', 'true');
        // Only load/display the new comment after posting (don't load all new comments since the page last loaded).
        // Grab the page title
        if ($this->Request->get('title')) {
            $this->Form->setValue('Name', $this->Request->get('title'));
        }
        // Set existing DiscussionID for comment form
        if ($Discussion) {
            $this->Form->addHidden('DiscussionID', $Discussion->DiscussionID);
        }
        foreach ($ForeignSource as $Key => $Val) {
            // Drop the foreign source information into the form so it can be used if creating a discussion
            $this->Form->addHidden($Key, $Val);
            // Also drop it into the definitions so it can be picked up for stashing comments
            $this->addDefinition($Key, $Val);
        }
        // Retrieve & apply the draft if there is one:
        $Draft = false;
        if (Gdn::session()->UserID && $Discussion) {
            $DraftModel = new DraftModel();
            $Draft = $DraftModel->get(Gdn::session()->UserID, 0, 1, $Discussion->DiscussionID)->firstRow();
            $this->Form->addHidden('DraftID', $Draft ? $Draft->DraftID : '');
        }
        if ($Draft) {
            $this->Form->setFormValue('Body', $Draft->Body);
        } else {
            // Look in the session stash for a comment
            $StashComment = Gdn::session()->getPublicStash('CommentForForeignID_' . $ForeignSource['vanilla_identifier']);
            if ($StashComment) {
                $this->Form->setValue('Body', $StashComment);
                $this->Form->setFormValue('Body', $StashComment);
            }
        }
        // Deliver JSON data if necessary
        if ($this->_DeliveryType != DELIVERY_TYPE_ALL) {
            if ($this->Discussion) {
                $this->setJson('LessRow', $this->Pager->toString('less'));
                $this->setJson('MoreRow', $this->Pager->toString('more'));
            }
            $this->View = 'comments';
        }
        // Ordering note for JS
        if ($SortComments == 'desc') {
            $this->addDefinition('PrependNewComments', '1');
        }
        // Report the discussion id so js can use it.
        if ($Discussion) {
            $this->addDefinition('DiscussionID', $Discussion->DiscussionID);
        }
        $this->fireEvent('BeforeDiscussionRender');
        $this->render();
    }
 /**
  * Discussions filter: Unresolved.
  *
  * @return void
  */
 public function discussionsController_unresolved_create($sender, $args)
 {
     $sender->permission('Plugins.Resolved.Manage');
     $page = val(0, $args, 0);
     // Determine offset from $Page
     list($page, $limit) = offsetLimit($page, C('Vanilla.Discussions.PerPage', 30));
     // Validate $Page
     if (!is_numeric($page) || $page < 0) {
         $page = 0;
     }
     $discussionModel = new DiscussionModel();
     $wheres = array('d.Resolved' => '0');
     // Hack in our wheregroup.
     Gdn::sql()->beginWhereGroup()->whereNotIn('d.Type', array('page', 'Report', 'poll', 'SimplePage'))->orWhere('d.Type is null')->endWhereGroup();
     $sender->DiscussionData = $discussionModel->Get($page, $limit, $wheres);
     $sender->setData('Discussions', $sender->DiscussionData);
     $countDiscussions = $discussionModel->GetCount($wheres);
     $sender->setData('CountDiscussions', $countDiscussions);
     $sender->Category = false;
     $sender->setJson('Loading', $page . ' to ' . $limit);
     // Build a pager
     $pagerFactory = new Gdn_PagerFactory();
     $sender->EventArguments['PagerType'] = 'Pager';
     $sender->fireEvent('BeforeBuildBookmarkedPager');
     $sender->Pager = $pagerFactory->getPager($sender->EventArguments['PagerType'], $sender);
     $sender->Pager->ClientID = 'Pager';
     $sender->Pager->configure($page, $limit, $countDiscussions, 'discussions/unresolved/%1$s');
     if (!$sender->data('_PagerUrl')) {
         $sender->setData('_PagerUrl', 'discussions/unresolved/{Page}');
     }
     $sender->setData('_Page', $page);
     $sender->setData('_Limit', $limit);
     $sender->fireEvent('AfterBuildBookmarkedPager');
     // Deliver JSON data if necessary
     if ($sender->deliveryType() != DELIVERY_TYPE_ALL) {
         $sender->setJson('LessRow', $sender->Pager->toString('less'));
         $sender->setJson('MoreRow', $sender->Pager->toString('more'));
         $sender->View = 'discussions';
     }
     // Add modules
     $sender->addModule('DiscussionFilterModule');
     $sender->addModule('NewDiscussionModule');
     $sender->addModule('CategoriesModule');
     // Render default view
     $sender->setData('Title', T('Unresolved'));
     $sender->setData('Breadcrumbs', array(array('Name' => T('Unresolved'), 'Url' => '/discussions/unresolved')));
     $sender->render('index');
 }
示例#5
0
 /**
  * Creates virtual 'Discussions' method in ProfileController.
  *
  * @since 2.0.0
  * @package Vanilla
  *
  * @param ProfileController $Sender ProfileController.
  */
 public function profileController_discussions_create($Sender, $UserReference = '', $Username = '', $Page = '', $UserID = '')
 {
     $Sender->editMode(false);
     // Tell the ProfileController what tab to load
     $Sender->getUserInfo($UserReference, $Username, $UserID);
     $Sender->_setBreadcrumbs(t('Discussions'), userUrl($Sender->User, '', 'discussions'));
     $Sender->setTabView('Discussions', 'Profile', 'Discussions', 'Vanilla');
     $Sender->CountCommentsPerPage = c('Vanilla.Comments.PerPage', 30);
     list($Offset, $Limit) = offsetLimit($Page, c('Vanilla.Discussions.PerPage', 30));
     $DiscussionModel = new DiscussionModel();
     $Discussions = $DiscussionModel->getByUser($Sender->User->UserID, $Limit, $Offset, false, Gdn::session()->UserID);
     $CountDiscussions = $Offset + $DiscussionModel->LastDiscussionCount + 1;
     $Sender->DiscussionData = $Sender->setData('Discussions', $Discussions);
     // Build a pager
     $PagerFactory = new Gdn_PagerFactory();
     $Sender->Pager = $PagerFactory->getPager('MorePager', $Sender);
     $Sender->Pager->MoreCode = 'More Discussions';
     $Sender->Pager->LessCode = 'Newer Discussions';
     $Sender->Pager->ClientID = 'Pager';
     $Sender->Pager->configure($Offset, $Limit, $CountDiscussions, userUrl($Sender->User, '', 'discussions') . '?page={Page}');
     // Deliver JSON data if necessary
     if ($Sender->deliveryType() != DELIVERY_TYPE_ALL && $Offset > 0) {
         $Sender->setJson('LessRow', $Sender->Pager->toString('less'));
         $Sender->setJson('MoreRow', $Sender->Pager->toString('more'));
         $Sender->View = 'discussions';
     }
     // Set the HandlerType back to normal on the profilecontroller so that it fetches it's own views
     $Sender->HandlerType = HANDLER_TYPE_NORMAL;
     // Do not show discussion options
     $Sender->ShowOptions = false;
     if ($Sender->Head) {
         // These pages offer only duplicate content to search engines and are a bit slow.
         $Sender->Head->addTag('meta', array('name' => 'robots', 'content' => 'noindex,noarchive'));
     }
     // Render the ProfileController
     $Sender->render();
 }
 /**
  * Filter the list of addons.
  *
  * @param string $FilterToType AddonModel::$TypesPlural and 'plugins,applications'.
  * @param string $Sort Order addons by popularity or recency.
  * @param string $Page Which page to display.
  */
 public function browse($FilterToType = '', $Sort = '', $Page = '')
 {
     // Create a virtual type called 'apps' as a stand-in for both plugins & applications.
     if ($FilterToType == 'apps') {
         $FilterToType = 'plugins,applications';
     }
     // Implement user prefs
     $Session = Gdn::session();
     if ($Session->isValid()) {
         if ($FilterToType != '') {
             $Session->setPreference('Addons.FilterType', $FilterToType);
         }
         //if ($VanillaVersion != '') {
         $Session->setPreference('Addons.FilterVanilla', '2');
         //}
         if ($Sort != '') {
             $Session->setPreference('Addons.Sort', $Sort);
         }
         $FilterToType = $Session->getPreference('Addons.FilterType', 'all');
         $VanillaVersion = $Session->getPreference('Addons.FilterVanilla', '2');
         $Sort = $Session->getPreference('Addons.Sort', 'recent');
     }
     $allowedFilters = AddonModel::$TypesPlural + ['plugins,applications' => true];
     if (!array_key_exists($FilterToType, $allowedFilters)) {
         $FilterToType = 'all';
     }
     if ($Sort != 'popular') {
         $Sort = 'recent';
     }
     if (!in_array($VanillaVersion, array('1', '2'))) {
         $VanillaVersion = '2';
     }
     $this->Version = $VanillaVersion;
     $this->Sort = $Sort;
     $this->FilterChecked = 'checked';
     $this->addJsFile('jquery.gardenmorepager.js');
     $this->addJsFile('browse.js');
     list($Offset, $Limit) = offsetLimit($Page, c('Garden.Search.PerPage', 20));
     $this->Filter = $FilterToType;
     if ($this->Filter == 'themes') {
         $Title = 'Browse Themes';
     } elseif ($this->Filter == 'plugins,applications') {
         $Title = 'Browse Plugins &amp; Applications';
     } else {
         $Title = 'Browse Addons';
     }
     $this->setData('Title', $Title);
     $Search = GetIncomingValue('Keywords', '');
     $this->buildBrowseWheres($Search);
     $SortField = $Sort == 'recent' ? 'DateUpdated' : 'CountDownloads';
     $ResultSet = $this->AddonModel->getWhere(false, $SortField, 'desc', $Limit, $Offset);
     $this->setData('Addons', $ResultSet);
     $this->buildBrowseWheres($Search);
     $NumResults = $this->AddonModel->getCount(false);
     $this->setData('TotalAddons', $NumResults);
     // Build a pager
     $PagerFactory = new Gdn_PagerFactory();
     $Pager = $PagerFactory->getPager('Pager', $this);
     $Pager->MoreCode = '›';
     $Pager->LessCode = '‹';
     $Pager->ClientID = 'Pager';
     $Pager->configure($Offset, $Limit, $NumResults, 'addon/browse/' . $FilterToType . '/' . $Sort . '/%1$s/?Keywords=' . urlencode($Search));
     $this->setData('_Pager', $Pager);
     if ($this->_DeliveryType != DELIVERY_TYPE_ALL) {
         $this->setJson('MoreRow', $Pager->toString('more'));
     }
     $this->addModule('AddonHelpModule');
     $this->render();
 }
 /**
  * Shows all uncleared messages within a conversation for the viewing user
  *
  * @since 2.0.0
  * @access public
  *
  * @param int $ConversationID Unique ID of conversation to view.
  * @param int $Offset Number to skip.
  * @param int $Limit Number to show.
  */
 public function index($ConversationID = false, $Offset = -1, $Limit = '')
 {
     $this->Offset = $Offset;
     $Session = Gdn::session();
     Gdn_Theme::section('Conversation');
     // Figure out Conversation ID
     if (!is_numeric($ConversationID) || $ConversationID < 0) {
         $ConversationID = 0;
     }
     // Form setup for adding comments
     $this->Form->setModel($this->ConversationMessageModel);
     $this->Form->addHidden('ConversationID', $ConversationID);
     // Check permissions on the recipients.
     $InConversation = $this->ConversationModel->inConversation($ConversationID, Gdn::session()->UserID);
     if (!$InConversation) {
         // Conversation moderation must be enabled and they must have permission
         if (!c('Conversations.Moderation.Allow', false)) {
             throw permissionException();
         }
         $this->permission('Conversations.Moderation.Manage');
     }
     $this->Conversation = $this->ConversationModel->getID($ConversationID);
     $this->Conversation->Participants = $this->ConversationModel->getRecipients($ConversationID);
     $this->setData('Conversation', $this->Conversation);
     // Bad conversation? Redirect
     if ($this->Conversation === false) {
         throw notFoundException('Conversation');
     }
     // Get limit
     if ($Limit == '' || !is_numeric($Limit) || $Limit < 0) {
         $Limit = Gdn::config('Conversations.Messages.PerPage', 50);
     }
     // Calculate counts
     if (!is_numeric($this->Offset) || $this->Offset < 0) {
         // Round down to the appropriate offset based on the user's read messages & messages per page
         $CountReadMessages = $this->Conversation->CountMessages - $this->Conversation->CountNewMessages;
         if ($CountReadMessages < 0) {
             $CountReadMessages = 0;
         }
         if ($CountReadMessages > $this->Conversation->CountMessages) {
             $CountReadMessages = $this->Conversation->CountMessages;
         }
         // (((67 comments / 10 perpage) = 6.7) rounded down = 6) * 10 perpage = offset 60;
         $this->Offset = floor($CountReadMessages / $Limit) * $Limit;
         // Send the hash link in.
         if ($CountReadMessages > 1) {
             $this->addDefinition('LocationHash', '#Item_' . $CountReadMessages);
         }
     }
     // Fetch message data
     $this->MessageData = $this->ConversationMessageModel->get($ConversationID, $Session->UserID, $this->Offset, $Limit);
     $this->EventArguments['MessageData'] = $this->MessageData;
     $this->fireEvent('beforeMessages');
     $this->setData('Messages', $this->MessageData);
     // Figure out who's participating.
     $ParticipantTitle = ConversationModel::participantTitle($this->Conversation, true);
     $this->Participants = $ParticipantTitle;
     $this->title(strip_tags($this->Participants));
     // $CountMessages = $this->ConversationMessageModel->getCount($ConversationID, $Session->UserID);
     // Build a pager
     $PagerFactory = new Gdn_PagerFactory();
     $this->Pager = $PagerFactory->getPager('MorePager', $this);
     $this->Pager->MoreCode = 'Newer Messages';
     $this->Pager->LessCode = 'Older Messages';
     $this->Pager->ClientID = 'Pager';
     $this->Pager->configure($this->Offset, $Limit, $this->Conversation->CountMessages, 'messages/' . $ConversationID . '/%1$s/%2$s/');
     // Mark the conversation as ready by this user.
     $this->ConversationModel->markRead($ConversationID, $Session->UserID);
     // Deliver json data if necessary
     if ($this->_DeliveryType != DELIVERY_TYPE_ALL) {
         $this->setJson('LessRow', $this->Pager->toString('less'));
         $this->setJson('MoreRow', $this->Pager->toString('more'));
         $this->View = 'messages';
     }
     // Add modules.
     $ClearHistoryModule = new ClearHistoryModule($this);
     $ClearHistoryModule->conversationID($ConversationID);
     $this->addModule($ClearHistoryModule);
     $InThisConversationModule = new InThisConversationModule($this);
     $InThisConversationModule->setData($this->Conversation->Participants);
     $this->addModule($InThisConversationModule);
     // Doesn't make sense for people who can't even start conversations to be adding people
     if (checkPermission('Conversations.Conversations.Add')) {
         $this->addModule('AddPeopleModule');
     }
     $Subject = $this->data('Conversation.Subject');
     if (!$Subject) {
         $Subject = t('Message');
     }
     $this->Data['Breadcrumbs'][] = array('Name' => $Subject, 'Url' => url('', '//'));
     // Render view
     $this->render();
 }
示例#8
0
 /**
  * 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(htmlspecialchars(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();
 }