DiscussionCustomPrefix: Added new icons and translations
[vanilla-miry.git] / extensions / DiscussionCustomPrefix / default.php
blob38757eeefedb97e7b437f571003bb6c9e2da8f2b
1 <?php
2 /*
3 Extension Name: Discussion Custom Prefix
4 Extension Url: http://lussumo.com/addons/
5 Description: Custom prefix for discussion.
6 Version: 0.01
7 Author: Roman "S" Vasiliev
8 Author Url: http://lussumo.com/community/account/8576/
9 */
11 if(!defined('IN_VANILLA')) die();
13 define('DCP_VERSION', 0.01);
14 define('DCP_PATH', $Configuration['EXTENSIONS_PATH'].'DiscussionCustomPrefix/');
15 define('DCP_ROOT', $Configuration['WEB_ROOT'].'extensions/DiscussionCustomPrefix/');
16 define('DCP_IMAGES', DCP_ROOT.'icons/');
18 $DatabaseColumns['Discussion']['CustomPrefixID'] = 'CustomPrefixID';
20 @$_VERSION = FloatVal($Configuration['DCP_VERSION']);
21 if($_VERSION != DCP_VERSION) require DCP_PATH.'setup.php';
23 switch($Context->SelfUrl){
24 case 'post.php':{
25 $Context->AddToDelegate('DiscussionForm', 'DiscussionForm_PreTopicRender', 'DCP_DiscussionForm_PreTopicRender');
26 $Context->AddToDelegate('DiscussionManager', 'PreSaveDiscussion', 'DCP_PreSaveDiscussion');
27 break;
29 case 'index.php':{
30 $Context->AddToDelegate('DiscussionGrid', 'Constructor', 'DCP_SetDelegateParameter');
31 $Context->AddToDelegate('DiscussionGrid', 'PreDiscussionOptionsRender', 'DCP_PreDiscussionOptionsRender');
32 break;
34 case 'comments.php':{
35 $Context->AddToDelegate('CommentGrid', 'Constructor', 'DCP_SetDelegateParameter');
36 $Context->AddToDelegate('CommentGrid', 'PreRender', 'DCP_CommentsPreRender');
37 break;
39 default: return;
42 $Context->AddToDelegate('DiscussionManager', 'PostGetDiscussionBuilder', 'DCP_PostGetDiscussionBuilder');
43 $Context->AddToDelegate('Discussion', 'PostGetPropertiesFromDataSet', 'DCP_PostGetPropertiesFromDataSet');
44 $Head->AddStyleSheet('extensions/DiscussionCustomPrefix/style.css');
46 function AddDiscussionCustomPrefixSelectStyles($Head) {
47 include DCP_PATH.'config.php';
48 $ListStyles='';
49 while(list($ID, $Info) = each($Config))
50 $ListStyles .= '.LargeSelect option.CustomPrefix_'.$ID.':before {content: url(extensions/DiscussionCustomPrefix/icons/'.$Info['img'].') !important;}'."\n";
51 $Head->AddString("<style type=\"text/css\">\n".$ListStyles."</style>\n");
54 AddDiscussionCustomPrefixSelectStyles($Head);
56 function GetDiscussionCustomPrefixSelect(&$Context, $Selected = 0){
57 $S = $Context->ObjectFactory->NewContextObject($Context, 'Select');
58 $S->Name = 'DiscussionCustomPrefix';
59 $S->SelectedValue = $Selected;
60 include DCP_PATH.'config.php';
61 $S->AddOption(0, $Context->GetDefinition('SelectOptionNoPrefix'));
62 while(list($ID, $Info) = each($Config))
63 $S->AddOption($ID, $Info['name'], ' class="CustomPrefix_'.$ID.'"');
64 return $S;
67 function DCP_DiscussionForm_PreTopicRender(&$DiscussionForm){
68 $Context =& $DiscussionForm->Context;
69 $CustomPrefixID = @$DiscussionForm->Discussion->CustomPrefixID;
70 $Text = $Context->GetDefinition('LabelTextDiscussionPrefix');
71 $Label = "<label for='DiscussionCustomPrefix'>$Text</label>";
72 $Select = GetDiscussionCustomPrefixSelect($Context, $CustomPrefixID)->Get();
73 printf('<li>%s%s</li>', $Label, $Select);
76 function DCP_SetDelegateParameter(&$UnknownGrid){
77 include DCP_PATH.'config.php'; // $Config
78 $UnknownGrid->DelegateParameters['CustomPrefixConfig'] = $Config;
81 function DCP_PostGetDiscussionBuilder(&$DiscussionManager){
82 $SqlBuilder =& $DiscussionManager->DelegateParameters['SqlBuilder'];
83 $SqlBuilder->AddSelect('CustomPrefixID', 't');
86 function DCP_PostGetPropertiesFromDataSet(&$Discussion){
87 $DataSet =& $Discussion->DelegateParameters['DataSet'];
88 @$Discussion->CustomPrefixID = ForceInt($DataSet['CustomPrefixID'], 0);
91 function DCP_PreSaveDiscussion(&$DiscussionManager){
92 $SqlBuilder =& $DiscussionManager->DelegateParameters['SqlBuilder'];
93 $CustomPrefixID = ForceIncomingInt('DiscussionCustomPrefix', 0);
94 $SqlBuilder->AddFieldNameValue('CustomPrefixID', $CustomPrefixID);
97 function DCP_PreDiscussionOptionsRender(&$DiscussionGrid){
98 $Discussion =& $DiscussionGrid->DelegateParameters['Discussion'];
99 $DiscussionList =& $DiscussionGrid->DelegateParameters['DiscussionList'];
100 $CustomPrefixConfig =& $DiscussionGrid->DelegateParameters['CustomPrefixConfig'];
101 $PrefixInfo = @$CustomPrefixConfig[$Discussion->CustomPrefixID];
102 if($PrefixInfo)
103 $DiscussionList .= '<img class="CustomPrefix" src="'.DCP_IMAGES.$PrefixInfo['img'].'" alt="'.$PrefixInfo['name'].'"> ';
106 function DCP_CommentsPreRender(&$CommentGrid){
107 $Discussion =& $CommentGrid->Discussion;
108 $CustomPrefixConfig =& $CommentGrid->DelegateParameters['CustomPrefixConfig'];
109 $PrefixInfo = @$CustomPrefixConfig[$Discussion->CustomPrefixID];
110 if($PrefixInfo)
111 $Discussion->Name = '<img class="CustomPrefix" src="'.DCP_IMAGES.$PrefixInfo['img'].'" alt="'.$PrefixInfo['name'].'"> '.$Discussion->Name;