Added extension: vanilla-voting-0.2beta-0.2beta.zip
[vanilla-miry.git] / extensions / VanillaVoting / default.php
blob04a7b313feefd8af1a54b28edfd1a431aff4d284
1 <?php
2 /*
3 Extension Name: Vanilla Voting
4 Extension Url: N/A
5 Description: Digg style voting
6 Version: 0.2beta
7 Author: Ziyad (MySchizoBuddy) Saeed
8 Author Url: N/A
12 // Vanilla Voting root path;
13 if (!defined('VANILLAVOTING_ROOT')) define('VANILLAVOTING_ROOT', dirname(__FILE__).'/');
14 $Configuration["VANILLAVOTING_PATH"] = 'extensions/VanillaVoting/';
16 $Context->Configuration['PERMISSION_VOTING_FOR_DISCUSSIONS'] = '0';
17 $Context->Configuration['PERMISSION_VOTING_FOR_COMMENTS'] = '0';
19 if( !array_key_exists('VANILLAVOTING_CATEGORYID', $Configuration)) {AddConfigurationSetting($Context, 'VANILLAVOTING_CATEGORYID', '');}
21 //Add the required database table and fields
22 if (!array_key_exists('VANILLAVOTING_VERSION', $Configuration)) {
23 $Errors = 0;
24 $UserDiscussionVoteTable = "CREATE TABLE `".$Configuration['DATABASE_TABLE_PREFIX']."UserDiscussionVote` (
25 `DiscussionID` int(8) NOT NULL,
26 `UserID` int(8) NOT NULL,
27 `Vote` tinyint(3) NOT NULL,
28 `DateCreated` datetime NOT NULL default '0000-00-00 00:00:00',
29 KEY `UserDiscussionVote_Key` (`DiscussionID`,`UserID`,`Vote`)
30 )";
32 $UserCommentVoteTable = "CREATE TABLE `".$Configuration['DATABASE_TABLE_PREFIX']."UserCommentVote` (
33 `CommentID` int(8) NOT NULL,
34 `UserID` int(8) NOT NULL,
35 `Vote` tinyint(3) NOT NULL,
36 `DateCreated` datetime NOT NULL default '0000-00-00 00:00:00',
37 KEY `UserCommentVote_Key` (`CommentID`,`UserID`,`Vote`)
38 )";
41 $AlterDiscussionTable = "ALTER TABLE `".$Configuration['DATABASE_TABLE_PREFIX']."Discussion` ADD `Vote` smallint(6) NOT NULL default '0';";
42 $AlterCommentTable = "ALTER TABLE `".$Configuration['DATABASE_TABLE_PREFIX']."Comment` ADD `Vote` smallint(6) NOT NULL default '0';";
44 if (!mysql_query($UserDiscussionVoteTable, $Context->Database->Connection)) $Errors = 1;
45 if (!mysql_query($UserCommentVoteTable, $Context->Database->Connection)) $Errors = 1;
46 if (!mysql_query($AlterDiscussionTable, $Context->Database->Connection)) $Errors = 1;
47 if (!mysql_query($AlterCommentTable, $Context->Database->Connection)) $Errors = 1;
48 $r= mysql_error();
50 if ($Errors == 0) {
51 // Add the db structure to the database configuration file
52 $Structure = "// Voting database structure for Discussions
53 \$DatabaseTables['UserDiscussionVote'] = 'UserDiscussionVote';
54 \$DatabaseColumns['UserDiscussionVote']['DiscussionID'] = 'DiscussionID';
55 \$DatabaseColumns['UserDiscussionVote']['UserID'] = 'UserID';
56 \$DatabaseColumns['UserDiscussionVote']['Vote'] = 'Vote';
57 \$DatabaseColumns['UserDiscussionVote']['DateCreated'] = 'DateCreated';
58 // Voting database structure for Comments
59 \$DatabaseTables['UserCommentVote'] = 'UserCommentVote';
60 \$DatabaseColumns['UserCommentVote']['CommentID'] = 'CommentID';
61 \$DatabaseColumns['UserCommentVote']['UserID'] = 'UserID';
62 \$DatabaseColumns['UserCommentVote']['Vote'] = 'Vote';
63 \$DatabaseColumns['UserCommentVote']['DateCreated'] = 'DateCreated';
64 // Vote field for the Discussion Table
65 \$DatabaseColumns['Discussion']['Vote'] = 'Vote';
66 // Vote field for the Comment Table
67 \$DatabaseColumns['Comment']['Vote'] = 'Vote';
69 if (!AppendToConfigurationFile($Configuration['APPLICATION_PATH'].'conf/database.php', $Structure)) $Errors = 1;
70 if ($Errors == 0) {
71 AddConfigurationSetting($Context, 'VANILLAVOTING_VERSION', '0.1');
72 } else {
73 // Could not save configuration
74 $NoticeCollector->AddNotice($Context->GetDefinition('ErrCreateConfig'));
78 if ($Context->SelfUrl == 'index.php' && $Context->Session->User->Permission('PERMISSION_VOTING_FOR_DISCUSSIONS')) {
80 require_once VANILLAVOTING_ROOT . 'language/English.php';
81 require_once VANILLAVOTING_ROOT . 'library/Class.DiscussionVote.php';
83 if (defined('JQUERY_EXTENSION')) {
84 if (!defined('JQUERY_INCLUDED')) {
85 includeJQuery();
88 } else {
89 $Head->AddScript($Configuration["VANILLAVOTING_PATH"].'js/jquery-1.2.1.pack.js');
92 $Head->AddScript($Configuration["VANILLAVOTING_PATH"].'js/AddVote.js.php');
93 $Head->AddStyleSheet($Configuration["VANILLAVOTING_PATH"].'theme/vote.css');
95 function DiscussionManager_InitDiscussionVote(&$DiscussionManager) {
96 $DiscussionVote = $DiscussionManager->Context->ObjectFactory->NewContextObject($DiscussionManager->Context, 'DiscussionVote');
97 $sql = &$DiscussionManager->DelegateParameters['SqlBuilder'];
98 $DiscussionVote->GetDiscussionVote(&$sql);
99 $DiscussionManager->Context->DelegateParameters['DiscussionVote'] = &$DiscussionVote;
102 $Context->AddToDelegate('DiscussionManager', 'PostGetDiscussionBuilder', 'DiscussionManager_InitDiscussionVote');
104 function DiscussionGrid_RenderDiscussionVote(&$DiscussionGrid) {
105 $DiscussionVote = &$DiscussionGrid->Context->DelegateParameters['DiscussionVote'];
106 $DataSet = &$DiscussionGrid->DelegateParameters['Discussion']->DelegateParameters['DataSet'];
107 $DiscussionList = &$DiscussionGrid->DelegateParameters['DiscussionList'];
108 $DiscussionVote->Render(&$DiscussionList, &$DataSet);
111 $Context->AddToDelegate('DiscussionGrid', 'PreDiscussionOptionsRender', 'DiscussionGrid_RenderDiscussionVote');
113 if ($Context->SelfUrl == 'comments.php' && $Context->Session->User->Permission('PERMISSION_VOTING_FOR_COMMENTS')) {
115 require_once VANILLAVOTING_ROOT . 'language/English.php';
116 require_once VANILLAVOTING_ROOT . 'library/Class.CommentVote.php';
118 if (defined('JQUERY_EXTENSION')) {
119 if (!defined('JQUERY_INCLUDED')) {
120 includeJQuery();
123 } else {
124 $Head->AddScript($Configuration["VANILLAVOTING_PATH"].'js/jquery-1.2.1.pack.js');
126 $Head->AddScript($Configuration["VANILLAVOTING_PATH"].'js/AddVote.js.php');
128 $Head->AddStyleSheet($Configuration["VANILLAVOTING_PATH"].'theme/vote.css');
130 function CommentManager_InitCommentVote(&$CommentManager) {
131 $CommentVote = $CommentManager->Context->ObjectFactory->NewContextObject($CommentManager->Context, 'CommentVote');
132 $sql = &$CommentManager->DelegateParameters['SqlBuilder'];
133 $CommentVote->GetCommentVote(&$sql);
134 $CommentManager->Context->DelegateParameters['CommentVote'] = &$CommentVote;
137 $Context->AddToDelegate('CommentManager', 'CommentBuilder_PreWhere', 'CommentManager_InitCommentVote');
139 function CommentGrid_RenderCommentVote(&$CommentGrid) {
140 $CommentVote = &$CommentGrid->Context->DelegateParameters['CommentVote'];
141 $DataSet = &$CommentGrid->DelegateParameters['Comment']->DelegateParameters['DataSet'];
142 $CommentList = &$CommentGrid->DelegateParameters['CommentList'];
143 $CommentVote->Render(&$CommentList, &$DataSet);
146 $Context->AddToDelegate('CommentGrid', 'PreCommentOptionsRender', 'CommentGrid_RenderCommentVote');
150 * Settings Panel. This is where all the forms are generated.
152 if(($Context->SelfUrl == 'settings.php') && $Context->Session->User->Permission('PERMISSION_CHANGE_APPLICATION_SETTINGS')) {
153 require_once VANILLAVOTING_ROOT . 'language/English.php';
154 require_once VANILLAVOTING_ROOT . 'library/PostBackControl.VanillaVotingForm.php';
156 $VanillaVotingForm= $Context->ObjectFactory->NewContextObject($Context, 'VanillaVotingForm');
157 $Page->AddRenderControl($VanillaVotingForm, $Configuration["CONTROL_POSITION_BODY_ITEM"]);
158 $ExtensionOptions = $Context->GetDefinition('Extension Options');
159 $Panel->AddList($ExtensionOptions);
160 $Panel->AddListItem($ExtensionOptions, $Context->GetDefinition('VanillaVoting'), GetUrl($Context->Configuration, 'settings.php', '', '', '', '', 'PostBackAction=VanillaVoting'));
163 if ($Context->SelfUrl == 'account.php' && $Context->Configuration['PERMISSION_ALLOW_VOTING_FOR_DISCUSSIONS']) {
164 require_once VANILLAVOTING_ROOT . 'language/English.php';
165 require_once VANILLAVOTING_ROOT . 'library/Class.VanillaVotingHistory.php';
167 if (defined('JQUERY_EXTENSION')) {
168 if (!defined('JQUERY_INCLUDED')) {
169 includeJQuery();
172 } else {
173 $Head->AddScript($Configuration["VANILLAVOTING_PATH"].'js/jquery-1.2.1.pack.js');
175 $Head->AddScript($Configuration["VANILLAVOTING_PATH"].'AddVote.js.php');
176 $Head->AddStyleSheet($Configuration["VANILLAVOTING_PATH"].'theme/vote.css');
178 $AccountUserID = ForceIncomingInt('u', $Context->Session->UserID);
179 $DiscussionVoteHistory = $Context->ObjectFactory->NewContextObject($Context, 'VanillaVotingHistory', $AccountUserID);
180 $Page->AddRenderControl($DiscussionVoteHistory, $Configuration["CONTROL_POSITION_BODY_ITEM"]);