3 Extension Name: Discussion Custom Prefix
4 Extension Url: http://lussumo.com/addons/
5 Description: Custom prefix for discussion.
7 Author: Roman "S" Vasiliev
8 Author Url: http://lussumo.com/community/account/8576/
11 if(!defined('IN_VANILLA')) die();
13 // You should cut & paste this language definition into your conf/your_language
14 $Context->SetDefinition('LabelTextDiscussionPrefix', 'Prefix');
15 $Context->SetDefinition('SelectOptionNoPrefix', 'no prefix');
17 define('DCP_VERSION', 0.01);
18 define('DCP_PATH', $Configuration['EXTENSIONS_PATH'].'DiscussionCustomPrefix/');
19 define('DCP_ROOT', $Configuration['WEB_ROOT'].'extensions/DiscussionCustomPrefix/');
20 define('DCP_IMAGES', DCP_ROOT
.'icons/');
22 $DatabaseColumns['Discussion']['CustomPrefixID'] = 'CustomPrefixID';
24 @$_VERSION = FloatVal($Configuration['DCP_VERSION']);
25 if($_VERSION != DCP_VERSION
) require DCP_PATH
.'setup.php';
27 switch($Context->SelfUrl
){
29 $Context->AddToDelegate('DiscussionForm', 'DiscussionForm_PreTopicRender', 'DCP_DiscussionForm_PreTopicRender');
30 $Context->AddToDelegate('DiscussionManager', 'PreSaveDiscussion', 'DCP_PreSaveDiscussion');
34 $Context->AddToDelegate('DiscussionGrid', 'Constructor', 'DCP_SetDelegateParameter');
35 $Context->AddToDelegate('DiscussionGrid', 'PreDiscussionOptionsRender', 'DCP_PreDiscussionOptionsRender');
39 $Context->AddToDelegate('CommentGrid', 'Constructor', 'DCP_SetDelegateParameter');
40 $Context->AddToDelegate('CommentGrid', 'PreRender', 'DCP_CommentsPreRender');
46 $Context->AddToDelegate('DiscussionManager', 'PostGetDiscussionBuilder', 'DCP_PostGetDiscussionBuilder');
47 $Context->AddToDelegate('Discussion', 'PostGetPropertiesFromDataSet', 'DCP_PostGetPropertiesFromDataSet');
48 $Head->AddStyleSheet('extensions/DiscussionCustomPrefix/style.css');
50 function AddDiscussionCustomPrefixSelectStyles($Head) {
51 include DCP_PATH
.'config.php';
53 while(list($ID, $Info) = each($Config))
54 $ListStyles .= '.LargeSelect option.CustomPrefix_'.$ID.':before {content: url(extensions/DiscussionCustomPrefix/icons/'.$Info['img'].') !important;}'."\n";
55 $Head->AddString("<style type=\"text/css\">\n".$ListStyles."</style>\n");
58 AddDiscussionCustomPrefixSelectStyles($Head);
60 function GetDiscussionCustomPrefixSelect(&$Context, $Selected = 0){
61 $S = $Context->ObjectFactory
->NewContextObject($Context, 'Select');
62 $S->Name
= 'DiscussionCustomPrefix';
63 $S->SelectedValue
= $Selected;
64 include DCP_PATH
.'config.php';
65 $S->AddOption(0, $Context->GetDefinition('SelectOptionNoPrefix'));
66 while(list($ID, $Info) = each($Config))
67 $S->AddOption($ID, $Info['name'], ' class="CustomPrefix_'.$ID.'"');
71 function DCP_DiscussionForm_PreTopicRender(&$DiscussionForm){
72 $Context =& $DiscussionForm->Context
;
73 $CustomPrefixID = @$DiscussionForm->Discussion
->CustomPrefixID
;
74 $Text = $Context->GetDefinition('LabelTextDiscussionPrefix');
75 $Label = "<label for='DiscussionCustomPrefix'>$Text</label>";
76 $Select = GetDiscussionCustomPrefixSelect($Context, $CustomPrefixID)->Get();
77 printf('<li>%s%s</li>', $Label, $Select);
80 function DCP_SetDelegateParameter(&$UnknownGrid){
81 include DCP_PATH
.'config.php'; // $Config
82 $UnknownGrid->DelegateParameters
['CustomPrefixConfig'] = $Config;
85 function DCP_PostGetDiscussionBuilder(&$DiscussionManager){
86 $SqlBuilder =& $DiscussionManager->DelegateParameters
['SqlBuilder'];
87 $SqlBuilder->AddSelect('CustomPrefixID', 't');
90 function DCP_PostGetPropertiesFromDataSet(&$Discussion){
91 $DataSet =& $Discussion->DelegateParameters
['DataSet'];
92 @$Discussion->CustomPrefixID
= ForceInt($DataSet['CustomPrefixID'], 0);
95 function DCP_PreSaveDiscussion(&$DiscussionManager){
96 $SqlBuilder =& $DiscussionManager->DelegateParameters
['SqlBuilder'];
97 $CustomPrefixID = ForceIncomingInt('DiscussionCustomPrefix', 0);
98 $SqlBuilder->AddFieldNameValue('CustomPrefixID', $CustomPrefixID);
101 function DCP_PreDiscussionOptionsRender(&$DiscussionGrid){
102 $Discussion =& $DiscussionGrid->DelegateParameters
['Discussion'];
103 $DiscussionList =& $DiscussionGrid->DelegateParameters
['DiscussionList'];
104 $CustomPrefixConfig =& $DiscussionGrid->DelegateParameters
['CustomPrefixConfig'];
105 $PrefixInfo = @$CustomPrefixConfig[$Discussion->CustomPrefixID
];
107 $DiscussionList .= '<img class="CustomPrefix" src="'.DCP_IMAGES
.$PrefixInfo['img'].'" alt="'.$PrefixInfo['name'].'"> ';
110 function DCP_CommentsPreRender(&$CommentGrid){
111 $Discussion =& $CommentGrid->Discussion
;
112 $CustomPrefixConfig =& $CommentGrid->DelegateParameters
['CustomPrefixConfig'];
113 $PrefixInfo = @$CustomPrefixConfig[$Discussion->CustomPrefixID
];
115 $Discussion->Name
= '<img class="CustomPrefix" src="'.DCP_IMAGES
.$PrefixInfo['img'].'" alt="'.$PrefixInfo['name'].'"> '.$Discussion->Name
;