/** * Add javascript to the post/edit discussion page so that tagging autocomplete works. * * @param PostController $Sender */ public function postController_render_before($Sender) { $Sender->addJsFile('jquery.tokeninput.js'); $Sender->addJsFile('tagging.js', 'plugins/Tagging'); $Sender->addDefinition('PluginsTaggingAdd', Gdn::session()->checkPermission('Plugins.Tagging.Add')); $Sender->addDefinition('PluginsTaggingSearchUrl', Gdn::request()->Url('plugin/tagsearch')); // Make sure that detailed tag data is available to the form. $TagModel = TagModel::instance(); $DiscussionID = val('DiscussionID', $Sender->Data['Discussion']); if ($DiscussionID) { $Tags = $TagModel->getDiscussionTags($DiscussionID, TagModel::IX_EXTENDED); $Sender->setData($Tags); } elseif (!$Sender->Request->isPostBack() && ($tagString = $Sender->Request->get('tags'))) { $tags = explodeTrim(',', $tagString); $types = array_column(TagModel::instance()->defaultTypes(), 'key'); // Look up the tags by name. $tagData = Gdn::sql()->getWhere('Tag', array('Name' => $tags, 'Type' => $types))->resultArray(); // Add any missing tags. $tagNames = array_change_key_case(array_column($tagData, 'Name', 'Name')); foreach ($tags as $tag) { $tagKey = strtolower($tag); if (!isset($tagNames[$tagKey])) { $tagData[] = array('TagID' => $tag, 'Name' => $tagKey, 'FullName' => $tag, 'Type' => ''); } } $Sender->setData('Tags', $tagData); } }
/** * Add needed resources to the page. * * @param PostController $sender Sending controller instance. * @param array $args Event's arguments. */ public function postController_render_before($sender, $args) { if (!$this->isWelcomePostActive($sender->Request, $categoryID)) { return; } $sender->addDefinition('WelcomePostPopupMessage', t('Please introduce yourself to the community!')); $sender->addJsFile('welcomepost.js', 'plugins/welcomepost'); $sender->addCssFile('welcomepost.css', 'plugins/welcomepost'); }