Add an "inform" message to be displayed to the user.
public informMessage ( string $Message, mixed $Options = ['CssClass' => 'Dismissable AutoDismiss'] ) | ||
$Message | string | The message to be displayed. |
$Options | mixed | An array of options for the message. If not an array, it is assumed to be a string of CSS classes to apply to the message. |
/** * Grabs all new notifications and adds them to the sender's inform queue. * * This method gets called by dashboard's hooks file to display new * notifications on every pageload. * * @since 2.0.18 * @access public * * @param Gdn_Controller $Sender The object calling this method. */ public static function informNotifications($Sender) { $Session = Gdn::session(); if (!$Session->isValid()) { return; } $ActivityModel = new ActivityModel(); // Get five pending notifications. $Where = array('NotifyUserID' => Gdn::session()->UserID, 'Notified' => ActivityModel::SENT_PENDING); // If we're in the middle of a visit only get very recent notifications. $Where['DateUpdated >'] = Gdn_Format::toDateTime(strtotime('-5 minutes')); $Activities = $ActivityModel->getWhere($Where, 0, 5)->resultArray(); $ActivityIDs = array_column($Activities, 'ActivityID'); $ActivityModel->setNotified($ActivityIDs); $Sender->EventArguments['Activities'] =& $Activities; $Sender->fireEvent('InformNotifications'); foreach ($Activities as $Activity) { if ($Activity['Photo']) { $UserPhoto = anchor(img($Activity['Photo'], array('class' => 'ProfilePhotoMedium')), $Activity['Url'], 'Icon'); } else { $UserPhoto = ''; } $Excerpt = Gdn_Format::plainText($Activity['Story']); $ActivityClass = ' Activity-' . $Activity['ActivityType']; $Sender->informMessage($UserPhoto . Wrap($Activity['Headline'], 'div', array('class' => 'Title')) . Wrap($Excerpt, 'div', array('class' => 'Excerpt')), 'Dismissable AutoDismiss' . $ActivityClass . ($UserPhoto == '' ? '' : ' HasIcon')); } }
/** * Dismiss a flag, then view index. * @param Gdn_Controller $Sender * @throws Exception * @throws Gdn_UserException */ public function controller_dismiss($Sender) { if (!Gdn::request()->isAuthenticatedPostBack(true)) { throw new Exception('Requires POST', 405); } if (Gdn::session()->checkPermission('Garden.Moderation.Manage')) { $Arguments = $Sender->RequestArgs; if (sizeof($Arguments) != 2) { return; } list($Controller, $EncodedURL) = $Arguments; $URL = base64_decode(str_replace('-', '=', $EncodedURL)); Gdn::sql()->delete('Flag', array('ForeignURL' => $URL)); $Sender->informMessage(sprintf(t('%s dismissed.'), t('Flag'))); } $Sender->render('blank', 'utility', 'dashboard'); }
/** * Delete a Tag * * @param Gdn_Controller $Sender */ public function controller_delete($Sender) { $Sender->permission('Garden.Settings.Manage'); $TagID = val(1, $Sender->RequestArgs); $TagModel = new TagModel(); $Tag = $TagModel->getID($TagID, DATASET_TYPE_ARRAY); if ($Sender->Form->authenticatedPostBack()) { // Delete tag & tag relations. $SQL = Gdn::sql(); $SQL->delete('TagDiscussion', array('TagID' => $TagID)); $SQL->delete('Tag', array('TagID' => $TagID)); $Sender->informMessage(formatString(t('<b>{Name}</b> deleted.'), $Tag)); $Sender->jsonTarget("#Tag_{$Tag['TagID']}", null, 'Remove'); } $Sender->setData('Title', t('Delete Tag')); $Sender->render('delete', '', 'plugins/Tagging'); }
/** * Add a method to the ModerationController to handle merging discussions. * * @param Gdn_Controller $Sender */ public function moderationController_mergeDiscussions_create($Sender) { $Session = Gdn::session(); $Sender->Form = new Gdn_Form(); $Sender->title(t('Merge Discussions')); $DiscussionModel = new DiscussionModel(); $CheckedDiscussions = Gdn::userModel()->getAttribute($Session->User->UserID, 'CheckedDiscussions', array()); if (!is_array($CheckedDiscussions)) { $CheckedDiscussions = array(); } $DiscussionIDs = $CheckedDiscussions; $Sender->setData('DiscussionIDs', $DiscussionIDs); $CountCheckedDiscussions = count($DiscussionIDs); $Sender->setData('CountCheckedDiscussions', $CountCheckedDiscussions); $Discussions = $DiscussionModel->SQL->whereIn('DiscussionID', $DiscussionIDs)->get('Discussion')->resultArray(); $Sender->setData('Discussions', $Discussions); // Make sure none of the selected discussions are ghost redirects. $discussionTypes = array_column($Discussions, 'Type'); if (in_array('redirect', $discussionTypes)) { throw Gdn_UserException('You cannot merge redirects.', 400); } // Perform the merge if ($Sender->Form->authenticatedPostBack()) { // Create a new discussion record $MergeDiscussion = false; $MergeDiscussionID = $Sender->Form->getFormValue('MergeDiscussionID'); foreach ($Discussions as $Discussion) { if ($Discussion['DiscussionID'] == $MergeDiscussionID) { $MergeDiscussion = $Discussion; break; } } $RedirectLink = $Sender->Form->getFormValue('RedirectLink'); if ($MergeDiscussion) { $ErrorCount = 0; // Verify that the user has permission to perform the merge. $Category = CategoryModel::categories($MergeDiscussion['CategoryID']); if ($Category && !$Category['PermsDiscussionsEdit']) { throw permissionException('Vanilla.Discussions.Edit'); } $DiscussionModel->defineSchema(); $MaxNameLength = val('Length', $DiscussionModel->Schema->getField('Name')); // Assign the comments to the new discussion record $DiscussionModel->SQL->update('Comment')->set('DiscussionID', $MergeDiscussionID)->whereIn('DiscussionID', $DiscussionIDs)->put(); $CommentModel = new CommentModel(); foreach ($Discussions as $Discussion) { if ($Discussion['DiscussionID'] == $MergeDiscussionID) { continue; } // Create a comment out of the discussion. $Comment = arrayTranslate($Discussion, array('Body', 'Format', 'DateInserted', 'InsertUserID', 'InsertIPAddress', 'DateUpdated', 'UpdateUserID', 'UpdateIPAddress', 'Attributes', 'Spam', 'Likes', 'Abuse')); $Comment['DiscussionID'] = $MergeDiscussionID; $CommentModel->Validation->results(true); $CommentID = $CommentModel->save($Comment); if ($CommentID) { // Move any attachments (FileUpload plugin awareness) if (class_exists('MediaModel')) { $MediaModel = new MediaModel(); $MediaModel->reassign($Discussion['DiscussionID'], 'discussion', $CommentID, 'comment'); } if ($RedirectLink) { // The discussion needs to be changed to a moved link. $RedirectDiscussion = array('Name' => SliceString(sprintf(t('Merged: %s'), $Discussion['Name']), $MaxNameLength), 'Type' => 'redirect', 'Body' => formatString(t('This discussion has been <a href="{url,html}">merged</a>.'), array('url' => DiscussionUrl($MergeDiscussion))), 'Format' => 'Html'); $DiscussionModel->setField($Discussion['DiscussionID'], $RedirectDiscussion); $CommentModel->updateCommentCount($Discussion['DiscussionID']); $CommentModel->removePageCache($Discussion['DiscussionID']); } else { // Delete discussion that was merged. $DiscussionModel->delete($Discussion['DiscussionID']); } } else { $Sender->informMessage($CommentModel->Validation->resultsText()); $ErrorCount++; } } // Update counts on all affected discussions. $CommentModel->updateCommentCount($MergeDiscussionID); $CommentModel->removePageCache($MergeDiscussionID); // Clear selections Gdn::userModel()->saveAttribute($Session->UserID, 'CheckedDiscussions', false); ModerationController::informCheckedDiscussions($Sender); if ($ErrorCount == 0) { $Sender->jsonTarget('', '', 'Refresh'); } } } $Sender->render('MergeDiscussions', '', 'plugins/SplitMerge'); }
/** * Fire before every page render. * * @param Gdn_Controller $Sender */ public function base_render_before($Sender) { $Session = Gdn::session(); // Check the statistics. if ($Sender->deliveryType() == DELIVERY_TYPE_ALL) { Gdn::statistics()->check(); } // Enable theme previewing if ($Session->isValid()) { $PreviewThemeName = htmlspecialchars($Session->getPreference('PreviewThemeName', '')); $PreviewThemeFolder = htmlspecialchars($Session->getPreference('PreviewThemeFolder', '')); if ($PreviewThemeName != '') { $Sender->Theme = $PreviewThemeName; $Sender->informMessage(sprintf(t('You are previewing the %s theme.'), wrap($PreviewThemeName, 'em')) . '<div class="PreviewThemeButtons">' . anchor(t('Apply'), 'settings/themes/' . $PreviewThemeName . '/' . $Session->transientKey(), 'PreviewThemeButton') . ' ' . anchor(t('Cancel'), 'settings/cancelpreview/', 'PreviewThemeButton') . '</div>', 'DoNotDismiss'); } } if ($Session->isValid()) { $Confirmed = val('Confirmed', Gdn::session()->User, true); if (UserModel::requireConfirmEmail() && !$Confirmed) { $Message = formatString(t('You need to confirm your email address.', 'You need to confirm your email address. Click <a href="{/entry/emailconfirmrequest,url}">here</a> to resend the confirmation email.')); $Sender->informMessage($Message, ''); } } // Add Message Modules (if necessary) $MessageCache = Gdn::config('Garden.Messages.Cache', array()); $Location = $Sender->Application . '/' . substr($Sender->ControllerName, 0, -10) . '/' . $Sender->RequestMethod; $Exceptions = array('[Base]'); if (in_array($Sender->MasterView, array('', 'default'))) { $Exceptions[] = '[NonAdmin]'; } // SignIn popup is a special case $SignInOnly = $Sender->deliveryType() == DELIVERY_TYPE_VIEW && $Location == 'Dashboard/entry/signin'; if ($SignInOnly) { $Exceptions = array(); } if ($Sender->MasterView != 'admin' && !$Sender->data('_NoMessages') && (val('MessagesLoaded', $Sender) != '1' && $Sender->MasterView != 'empty' && ArrayInArray($Exceptions, $MessageCache, false) || InArrayI($Location, $MessageCache))) { $MessageModel = new MessageModel(); $MessageData = $MessageModel->getMessagesForLocation($Location, $Exceptions, $Sender->data('Category.CategoryID')); foreach ($MessageData as $Message) { $MessageModule = new MessageModule($Sender, $Message); if ($SignInOnly) { // Insert special messages even in SignIn popup echo $MessageModule; } elseif ($Sender->deliveryType() == DELIVERY_TYPE_ALL) { $Sender->addModule($MessageModule); } } $Sender->MessagesLoaded = '1'; // Fixes a bug where render gets called more than once and messages are loaded/displayed redundantly. } if ($Sender->deliveryType() == DELIVERY_TYPE_ALL) { $Gdn_Statistics = Gdn::factory('Statistics'); $Gdn_Statistics->check($Sender); } // Allow forum embedding if ($Embed = c('Garden.Embed.Allow')) { // Record the remote url where the forum is being embedded. $RemoteUrl = c('Garden.Embed.RemoteUrl'); if (!$RemoteUrl) { $RemoteUrl = GetIncomingValue('remote'); if ($RemoteUrl) { saveToConfig('Garden.Embed.RemoteUrl', $RemoteUrl); } } if ($RemoteUrl) { $Sender->addDefinition('RemoteUrl', $RemoteUrl); } if ($remoteUrlFormat = c('Garden.Embed.RemoteUrlFormat')) { $Sender->addDefinition('RemoteUrlFormat', $remoteUrlFormat); } // Force embedding? if (!IsSearchEngine() && strtolower($Sender->ControllerName) != 'entry') { if (IsMobile()) { $forceEmbedForum = c('Garden.Embed.ForceMobile') ? '1' : '0'; } else { $forceEmbedForum = c('Garden.Embed.ForceForum') ? '1' : '0'; } $Sender->addDefinition('ForceEmbedForum', $forceEmbedForum); $Sender->addDefinition('ForceEmbedDashboard', c('Garden.Embed.ForceDashboard') ? '1' : '0'); } $Sender->addDefinition('Path', Gdn::request()->path()); $get = Gdn::request()->get(); unset($get['p']); // kludge for old index.php?p=/path $Sender->addDefinition('Query', http_build_query($get)); // $Sender->addDefinition('MasterView', $Sender->MasterView); $Sender->addDefinition('InDashboard', $Sender->MasterView == 'admin' ? '1' : '0'); if ($Embed === 2) { $Sender->addJsFile('vanilla.embed.local.js'); } else { $Sender->addJsFile('embed_local.js'); } } else { $Sender->setHeader('X-Frame-Options', 'SAMEORIGIN'); } // Allow return to mobile site $ForceNoMobile = val('X-UA-Device-Force', $_COOKIE); if ($ForceNoMobile === 'desktop') { $Sender->addAsset('Foot', wrap(Anchor(t('Back to Mobile Site'), '/profile/nomobile/1'), 'div'), 'MobileLink'); } // Allow global translation of TagHint $Sender->addDefinition("TagHint", t("TagHint", "Start to type...")); }