Vanilla 1 is no longer supported or maintained. If you need a copy, you can get it here.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.
Help with an extension
merfed
New
I'm trying to make an extension and I'm completely new to this. My goal is to create a thread "description" area. That will show under the thread name in the thread listing. How would I go about do this? Pointing me in the right direction would be great.
0
Comments
// Definitions $Context->Dictionary["TopicDesc"] = "Topic Abstract"; $Context->Dictionary["ErrInstallExtension"] = "LOL CAN'T SEE SHIT CAPN'"; // Install if (!array_key_exists('TOPICDESC', $Configuration)) { $DropTopicDesc = 'DROP TABLE IF EXISTS `' . $Context->Configuration['DATABASE_TABLE_PREFIX'] . 'TopicDesc`'; $CreateTopicDesc = 'CREATE TABLE `' . $Context->Configuration['DATABASE_TABLE_PREFIX'] . 'TopicDesc` (' . '`Desc` varchar(255) NOT NULL,' . '`DiscussionID int NOT NULL)'; $errors = 0; $connection = $Context->Database->GetConnection(); if (!mysql_query($DropTopicDesc, $connection)) $errors++; if (!mysql_query($CreateTopicDesc, $connection)) $errors++; if ($errors > 0) { $Context->WarningCollector->Add($Context->GetDefinition('ErrInstallExtension')); } else { AddConfigurationSetting($Context, 'TOPICDESC', '1'); } } // Database $DatabaseTables['TopicDesc'] = 'TopicDesc'; $DatabaseColumns['TopicDesc']['Desc'] = 'Desc'; $DatabaseColumns['TopicDesc']['DiscussionID'] = 'DiscussionID'; // Delegates $Context->AddToDelegate("DiscussionForm", "DiscussionForm_PreCommentRender", "AddTopicAbstract"); $Context->AddToDelegate("DiscussionForm", "PostSaveDiscussion", "SaveTopicDesc"); // Save Topic Desc function SaveTopicDesc(&$DiscussionForm) { global $Context; if( $Discussion = &$DiscussionForm->DelegateParameters['ResultDiscussion'] ) { foreach ($TopicDesc as &$TopicDesc) { if ($TopicDesc > "") { $query = "INSERT INTO `".$Context->Configuration['DATABASE_TABLE_PREFIX']."TopicDesc` (`Desc`, `DiscussionID`) VALUES ('".FormatStringForDatabaseInput($TopicDesc)."', '".$DiscussionForm->DelegateParameters['ResultDiscussion']->DiscussionID."');"; $result = $Context->Database->Execute($query,'','','An error occured adding a topic description.'); } } } } // Get Topic Desc function GetTopicDesc($DiscussionID) { global $Context; //$query = "SELECT Desc FROM `".$Context->Configuration['DATABASE_TABLE_PREFIX']."TopicDesc` as t LEFT JOIN `".$Context->Configuration['DATABASE_TABLE_PREFIX']."Discussion` as d ON t.DiscussionID = d.DiscussionID WHERE t.DiscussionID = '".$DiscussionID."' AND Active = 1;"; //$result = $Context->Database->Execute($query,'','','An error occured getting Topic Desc for this discussions.'); $TopicDescValue = ""; while (@$row = $Context->Database->GetRow($result)) { $TopicDescValue.= $row['Desc'] . ", "; } return $TopicDescValue; } // Add to Discussion Form function AddTopicAbstract(&$DiscussionForm) { global $Context; $TopicDescList = GetTopicDesc($DiscussionForm->DiscussionID); echo '<li> <label for="txtDesc">'.$Context->GetDefinition('TopicDesc').'</label> <input id="txtDesc" type="text" name="TopicDesc" class="DiscussionBox" value="'.$TopicDescList.'" /> </li>'; }
<?php /* Extension Name: Topic Descriptions Extension Url: none Description: Allows topic descriptions to be set Version: 1.0 Author: merfed Author Url: none */ // Definitions $Context->Dictionary["TopicDesc"] = "Topic Abstract"; $Context->Dictionary["ErrInstallExtension"] = "LOL CAN'T SEE SHIT CAPN'"; // Install if (!array_key_exists('TOPICDESC', $Configuration)) { $DropTopicDesc = 'DROP TABLE IF EXISTS `' . $Context->Configuration['DATABASE_TABLE_PREFIX'] . 'TopicDesc`'; $CreateTopicDesc = 'CREATE TABLE `' . $Context->Configuration['DATABASE_TABLE_PREFIX'] . 'TopicDesc` (' . '`ThreadDesc` varchar(255) NOT NULL,' . '`DiscussionID` int NOT NULL)'; $errors = 0; $connection = $Context->Database->GetConnection(); if (!mysql_query($DropTopicDesc, $connection)) $errors++; if (!mysql_query($CreateTopicDesc, $connection)) $errors++; if ($errors > 0) { $Context->WarningCollector->Add($Context->GetDefinition('ErrInstallExtension')); } else { AddConfigurationSetting($Context, 'TOPICDESC', '1'); } } // Database $DatabaseTables['TopicDesc'] = 'TopicDesc'; $DatabaseColumns['TopicDesc']['ThreadDesc'] = 'ThreadDesc'; $DatabaseColumns['TopicDesc']['DiscussionID'] = 'DiscussionID'; // Delegates $Context->AddToDelegate("DiscussionForm", "DiscussionForm_PreCommentRender", "AddTopicAbstract"); $Context->AddToDelegate("DiscussionForm", "PostSaveDiscussion", "SaveTopicDesc"); // Save Topic Desc function SaveTopicDesc(&$DiscussionForm) { global $Context; if ($Discussion = &$DiscussionForm->DelegateParameters['ResultDiscussion']) { if (!isset($TopicDesc)) { return; } if ($TopicDesc > "") { $query = "INSERT INTO `".$Context->Configuration['DATABASE_TABLE_PREFIX']."TopicDesc` (`ThreadDesc`, `DiscussionID`) VALUES ('".FormatStringForDatabaseInput($TopicDesc)."', '".$DiscussionForm->DelegateParameters['ResultDiscussio']->DiscussionID."');"; $result = $Context->Database->Execute($query,'','','An error occured adding a topic description.'); } } } // Get Topic Desc function GetTopicDesc($DiscussionID) { global $Context; /* New Database Pull Code $dbPullThreads = $Context->ObjectFactory->NewContextObject($Context, 'SqlBuilder'); $dbPullThreads->SetMainTable('User', 'User'); $dbPullThreads->AddSelect('CountDiscussions', 'User'); $dbPullThreads->AddWhere('User', 'UserID', '', $Context->Session->User->UserID, '=', 'AND', '', 0); $PullDiscussions = $Context->Database->Select($dbPullThreads, 'Points', 'PullUserDetails', 'An error occured while attempting to retrieve Discussion Count'); while($row = $Context->Database->GetRow($PullDiscussions)) { if(!isset($row['CountDiscussions'])) continue; $Points_Count_Threads = $row['CountDiscussions']; } $query = "SELECT Desc FROM `".$Context->Configuration['DATABASE_TABLE_PREFIX']."TopicDesc` as t LEFT JOIN `".$Context->Configuration['DATABASE_TABLE_PREFIX']."Discussion` as d ON t.DiscussionID = d.DiscussionID WHERE t.DiscussionID = '".$DiscussionID."' AND Active = 1;"; $result = $Context->Database->Execute($query,'','','An error occured getting Topic Desc for this discussions.'); $TopicDescValue = ""; while (@$row = $Context->Database->GetRow($result)) { $TopicDescValue.= $row['Desc'] . ", "; } return $TopicDescValue; } // Add to Discussion Form function AddTopicAbstract(&$DiscussionForm) { global $Context; $TopicDesc = GetTopicDesc($DiscussionForm->DiscussionID); echo '<li> <label for="txtDesc">'.$Context->GetDefinition('TopicDesc').'</label> <input id="txtDesc" type="text" name="TopicDesc" class="DiscussionBox" value="'.$TopicDesc.'" /> </li>'; } ?>