/** * Insert MathJax javascript into discussion pages * * @param DiscussionController $sender */ public function DiscussionController_Render_Before(&$sender) { // Add basic MathJax configuration $mathJaxConfig = <<<MATHJAX <script type="text/x-mathjax-config"> MathJax.Hub.Config({ jax: ["input/TeX","output/HTML-CSS"], extensions: ["tex2jax.js","MathMenu.js","MathZoom.js"], TeX: { extensions: ["AMSmath.js","AMSsymbols.js","noErrors.js","noUndefined.js"] }, tex2jax: { inlineMath: [ ['\$\\(','\\)\$'] ], displayMath: [ ['\$\$\\(','\\)\$\$'] ], processEscapes: true }, "HTML-CSS": { availableFonts: ["TeX"] }, messageStyle: "none", showProcessingMessages: false }); </script> MATHJAX; $sender->Head->addString($mathJaxConfig); $sender->addJsFile("http://cdn.mathjax.org/mathjax/2.4-latest/MathJax.js?delayStartupUntil=onload"); $sender->addJsFile("live.js", "plugins/MathJax"); }
/** * @param DiscussionController $Sender */ public function DiscussionController_Render_Before($Sender) { // Get the tags on this discussion. $Tags = TagModel::instance()->getDiscussionTags($Sender->Data('Discussion.DiscussionID'), TagModel::IX_EXTENDED); foreach ($Tags as $Key => $Value) { SetValue($Key, $Sender->Data['Discussion'], $Value); } }
/** * Write information about addons to the discussion if it is related to an addon. * * @param DiscussionController $Sender */ public function discussionController_afterDiscussionTitle_handler($Sender) { $Discussion = $Sender->data('Discussion'); $AddonID = val('AddonID', $Discussion); if (is_numeric($AddonID) && $AddonID > 0) { $Data = Gdn::database()->sql()->select('Name')->from('Addon')->where('AddonID', $AddonID)->get()->firstRow(); if ($Data) { echo renderDiscussionAddonWarning($AddonID, $Data->Name, val('DiscussionID', $Discussion)); } } }
protected function executeImpl(ArrayAdapter $params) { $unique = $params->str(DiscussionController::JS_DATA_UNIQUE); $upDown = $params->bool(DiscussionController::JS_DATA_UPDOWN); $entity = $params->int(DiscussionController::JS_DATA_THREAD); $action = $params->str(self::JS_PARAM_ACTION); $msgId = $params->int(self::JS_PARAM_MSG_ID); $rootId = $params->int(self::JS_PARAM_ROOT_ID); $controller = Handlers::getInstance()->getDiscussionController($unique); if (in_array($action, DiscussionController::getCommentActions())) { return new AjaxSuccess($controller->executeCommentAction($msgId, $action)); } if ($action == DiscussionController::TREE_ACTION_LOAD_COMMENTS) { return new AjaxSuccess($controller->loadTree($rootId, $upDown, $entity)); } return "Неизвестное действие: [{$action}]"; }
/** * Add or subtract a value from a comment's score. * @param DiscussionController $Sender The controller that is implementing this method. * @param array $Args The arguments for the operation. */ public function DiscussionController_Score_Create($Sender, $Args) { $CommentID = $Args[0]; $ScoreKey = substr($Args[1], 0, 3) == 'Neg' ? -1 : 1; //$TransientKey = $Args[2]; $SQL = Gdn::SQL(); $Session = Gdn::Session(); // Get the current score for this user. $Data = $SQL->Select('uc.Score')->From('UserComment uc')->Where('uc.CommentID', $CommentID)->Where('uc.UserID', $Session->UserID)->Get()->FirstRow(); $UserScore = $Data ? $Data->Score : 0; // Get the score increments. $Inc = $this->GetScoreIncrements($CommentID, $UserScore); $Score = $Inc[$ScoreKey]; $UserScore += $Score; if ($Score != 0) { if ($Data) { // Update the score on an existing comment. $SQL->Update('UserComment')->Set('Score', $UserScore)->Set('DateUpdated', Format::ToDateTime())->Set('UpdateUserID', $Session->UserID)->Where('UserID', $Session->UserID)->Where('CommentID', $CommentID)->Put(); } else { // Insert a new score. $SQL->Insert('UserComment', array('CommentID' => $CommentID, 'UserID' => $Session->UserID, 'Score' => $UserScore, 'DateInserted' => Format::ToDateTime(), 'InsertUserID' => $Session->UserID, 'DateUpdated' => Format::ToDateTime(), 'UpdateUserID' => $Session->UserID)); } // Update the comment table with the sum of the scores. $Data = $SQL->Select('uc.Score', 'sum', 'SumScore')->From('UserComment uc')->Where('uc.CommentID', $CommentID)->Get()->FirstRow(); $SumScore = $Data ? $Data->SumScore : 0; $SQL->Update('Comment')->Set('SumScore', $SumScore)->Where('CommentID', $CommentID)->Put(); $Inc = $this->GetScoreIncrements($CommentID, $UserScore); } // Redirect back where the user came from if necessary if ($Sender->DeliveryType() != DELIVERY_TYPE_BOOL) { $Target = GetIncomingValue('Target', '/vanilla/discussions/scored'); Redirect($Target); } // Send the current information back to be dealt with on the client side. $Sender->SetJson('SumScore', isset($SumScore) ? sprintf(Plural($SumScore, '%s point', '%s points'), $SumScore) : NULL); $Sender->SetJson('Inc', $Inc); $Sender->Render(); break; }
/** * @param DiscussionController $Sender */ public function DiscussionController_Render_Before($Sender, $Args) { $ConversationID = $Sender->Data('Discussion.Attributes.WhisperConversationID'); if (!$ConversationID) { return; } if ($ConversationID === TRUE) { $UserIDs = $Sender->Data('Discussion.Attributes.WhisperUserIDs'); // Grab the users that are in the conversaton. $WhisperUsers = array(); foreach ($UserIDs as $UserID) { $WhisperUsers[] = array('UserID' => $UserID); } } else { // There is already a conversation so grab its users. $WhisperUsers = Gdn::SQL()->Select('UserID')->From('UserConversation')->Where('ConversationID', $ConversationID)->Where('Deleted', 0)->Get()->ResultArray(); $UserIDs = ConsolidateArrayValuesByKey($WhisperUsers, 'UserID'); } if (!Gdn::Session()->CheckPermission('Conversations.Moderation.Manage') && !in_array(Gdn::Session()->UserID, $UserIDs)) { $Sender->Data['Discussion']->Closed = TRUE; return; } Gdn::UserModel()->JoinUsers($WhisperUsers, array('UserID')); $Sender->SetData('WhisperUsers', $WhisperUsers); }
/** * * @param DiscussionController $Sender * @param type $Args * @return type */ public function DiscussionController_AfterDiscussion_Handler($Sender, $Args) { if ($Sender->Data('Answers')) { include $Sender->FetchViewLocation('Answers', '', 'plugins/QnA'); } }
/** * Disallow comments in Resolved discussions by new participants. * * @param DiscussionController $sender */ public function discussionController_beforeDiscussionRender_handler($sender, $args) { $discussion = $sender->data('Discussion'); // Do not close blog comments. if ('page' == val('Type', $discussion)) { return; } $resolved = val('Resolved', $discussion); $isStarter = val('InsertUserID', $discussion) == Gdn::session()->UserID; if (!checkPermission('Plugins.Resolved.Manage') && $resolved && !$isStarter) { // Pretend we're closed svalr('Closed', $discussion, 1); $sender->setData('Discussion', $discussion); } }
/** * Add 'Ask a Question' button if using BigButtons. * * @param DiscussionController $sender Sending controller instance. */ public function discussionController_render_before($sender) { if (c('Plugins.QnA.UseBigButtons')) { $QuestionModule = new NewQuestionModule($sender, 'plugins/QnA'); $sender->addModule($QuestionModule); } if ($sender->data('Discussion.Type') == 'Question') { $sender->setData('_CommentsHeader', t('Answers')); } }
function __construct(CommentsProcessor $commentsProcessor) { $this->CP = $commentsProcessor; parent::__construct(); }
protected function getRequiredParamKeys() { return array_merge(DiscussionController::getJsDataKeys(), PsUtil::getClassConsts(__CLASS__, 'JS_PARAM_')); }