Changeset 816 for trunk/Modules/Forum
- Timestamp:
- Feb 22, 2015, 11:20:50 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Modules/Forum/Forum.php
r805 r816 3 3 class ModuleForum extends AppModule 4 4 { 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 'Title' => T('Forum'), 'Channel' => 'forum', 'Callback' => array('PageForum', 'ShowRSS'),21 'Permission' => LICENCE_ANONYMOUS));22 5 function __construct($System) 6 { 7 parent::__construct($System); 8 $this->Name = 'Forum'; 9 $this->Version = '1.0'; 10 $this->Creator = 'Maron'; 11 $this->License = 'GNU/GPL'; 12 $this->Description = ''; 13 $this->Dependencies = array(); 14 } 15 16 function Start() 17 { 18 $this->System->RegisterPage('forum', 'PageForum'); 19 $this->System->ModuleManager->Modules['News']->RegisterRSS(array( 20 'Title' => T('Forum'), 'Channel' => 'forum', 'Callback' => array('PageForum', 'ShowRSS'), 21 'Permission' => LICENCE_ANONYMOUS)); 22 23 23 if(array_key_exists('Search', $this->System->ModuleManager->Modules)) 24 24 $this->System->ModuleManager->Modules['Search']->RegisterSearch('forum', … … 27 27 $this->System->ModuleManager->Modules['Search']->RegisterSearch('forumthread', 28 28 T('Name of thread forum'), array('UserName', 'Text'), '`ForumThread`', $this->System->Link('/forum/?search=')); 29 29 30 30 $this->System->RegisterMenuItem(array( 31 31 'Title' => T('Forum'), … … 35 35 'Icon' => '', 36 36 ), 17); 37 37 } 38 38 } 39 39 40 40 class PageForum extends Page 41 41 { 42 43 44 $Output = ''; 45 46 47 42 function Show() 43 { 44 $Output = ''; 45 $this->Title = T('Forum'); 46 if(array_key_exists('a', $_POST)) $Action = $_POST['a']; 47 else if(array_key_exists('a', $_GET)) $Action = $_GET['a']; 48 48 else $Action = ''; 49 49 if (array_key_exists('Edit', $_GET)) { 50 if (array_key_exists('text', $_POST)) 51 $Output .= $this->Edit(); 50 if (array_key_exists('text', $_POST)) 51 $Output .= $this->Edit(); 52 52 $Output .= $this->ShowEditForm(); 53 53 54 54 } else 55 55 if (array_key_exists('search', $_GET)) … … 57 57 else 58 58 if (array_key_exists('Thread', $_GET)) { 59 60 61 62 59 $Output .= '<h3>'.T('Forum - Thread').'</h3>'; 60 if($Action == 'add2') $Output .= $this->AddFinish(); 61 if($this->System->User->Licence(LICENCE_USER)) $Output .= $this->ShowAddForm(); 62 $Output .= $this->ShowList(); 63 63 } else { 64 65 66 64 $Output .= '<h3>'.T('Forum - List of Thread').'</h3>'; 65 if($Action == 'add2') $Output .= $this->AddFinish('ForumThread'); 66 if($this->System->User->Licence(LICENCE_USER)) $Output .= $this->ShowAddFormThread(); 67 67 $Output .= $this->ShowListThread(); 68 68 } 69 70 71 72 function Edit() 73 { 74 $Output = ''; 75 76 77 78 79 69 return($Output); 70 } 71 72 function Edit() 73 { 74 $Output = ''; 75 76 $Text = $_POST['text']; 77 78 $DbResult = $this->System->Database->query('UPDATE `ForumText` SET `Text`="'.$_POST['text'].'" WHERE `User` = '.$this->System->User->Id.' AND `ID` = '.$_GET['Edit']); 79 80 80 $Output .= ShowMessage(T('Text edited.')); 81 81 82 82 83 83 return ($Output); 84 84 } 85 86 87 88 89 90 91 85 86 function ShowEditForm() 87 { 88 $Output = ''; 89 if($this->System->User->Licence(LICENCE_USER)) 90 { 91 $DbResult = $this->System->Database->query('SELECT * FROM `ForumText` WHERE `User` = '.$this->System->User->Id.' AND `ID` = '.$_GET['Edit']); 92 92 if ( $DbResult->num_rows > 0) { 93 93 $DbRow = $DbResult->fetch_assoc(); 94 95 96 97 98 99 $Output .= T('Message text').': ('.T('You can use').' <a href="http://www.bbcode.org/reference.php">'.T('BB code').'</a>)<br/>'.100 101 102 103 104 }else $Output .= ShowMessage(T('You have to be registered for adding message.'), MESSAGE_CRITICAL);105 } 106 return($Output); 107 108 109 94 $Output .= '<form action="?Edit='.$_GET['Edit'].'" method="post">'. 95 '<fieldset><legend>'.T('Edit message').'</legend>'. 96 T('User').': '; 97 if($this->System->User->Licence(LICENCE_USER)) $Output .= '<b>'.$this->System->User->Name.'</b><br />'; 98 else $Output .= '<input type="text" name="user" /><br />'; 99 $Output .= T('Message text').': ('.T('You can use').' <a href="http://www.bbcode.org/reference.php">'.T('BB code').'</a>)<br/>'. 100 '<textarea onkeydown="ResizeTextArea(this)" rows="8" name="text" cols="80">'.$DbRow['Text'].'</textarea> <br/>'. 101 '<input type="hidden" name="a" value="add2"/>'. 102 '<input type="submit" value="'.T('Send').'" /><br /></fieldset>'. 103 '</form>'; 104 } else $Output .= ShowMessage(T('You have to be registered for adding message.'), MESSAGE_CRITICAL); 105 } else $Output .= ShowMessage(T('You can edit only your own message.'), MESSAGE_CRITICAL); 106 return($Output); 107 } 108 109 function ShowSearchForum() 110 110 { 111 111 $parser = new HTML_BBCodeParser2(array('filters' => array('Basic','Extended','Images','Links','Lists','Email'))); 112 113 114 115 112 $Count = 20; 113 $Output = ''; 114 115 $Output .= '<div class="shoutbox">'; 116 116 $where = '`ForumText`.`Text` LIKE "%'.($_GET['search'] ).'%" OR '. 117 117 ' `ForumThread`.`Text` LIKE "%'.($_GET['search'] ).'%" OR `ForumThread`.`UserName` LIKE "%'.($_GET['search'] ).'%" OR '. … … 119 119 $join = ' JOIN `ForumThread` ON `ForumThread`.`ID` = `ForumText`.`Thread`'; 120 120 121 122 123 $PageList = GetPageList($DbRow[0]); 124 125 126 127 121 $DbResult = $this->System->Database->query('SELECT COUNT(*) FROM `ForumText` '.$join.' WHERE '.$where); 122 $DbRow = $DbResult->fetch_row(); 123 $PageList = GetPageList($DbRow[0]); 124 125 $Output .= $PageList['Output']; 126 127 $DbResult = $this->System->Database->query('SELECT `ForumText`.`Text`, `ForumText`.`Date`, `ForumText`.`UserName`,'. 128 128 '`ForumThread`.`Text` as `ThreadName`,`ForumText`.`Thread` FROM `ForumText` '.$join.' WHERE '.$where.' ORDER BY `ForumText`.`Date` DESC '.$PageList['SQLLimit']); 129 130 131 132 133 } 134 135 136 137 138 139 140 141 $PageList = GetPageList($DbRow[0]); 142 143 144 145 146 147 148 149 150 151 152 153 154 155 129 while($Line = $DbResult->fetch_assoc()) 130 $Output .= '<div><a href="'.$this->System->Link('/forum/?Thread='.$Line['Thread']).'">'.$Line['ThreadName'].'</a><br /><strong>'.$Line['UserName'].'</strong> ('.HumanDate($Line['Date']).'): '.$parser->qparse($Line['Text']).'</div> '; 131 $Output .= '</div>'.$PageList['Output']; 132 return($Output); 133 } 134 135 function ShowListThread() 136 { 137 $Output = ''; 138 139 $DbResult = $this->System->Database->query('SELECT COUNT(*) FROM `ForumThread` WHERE 1'); 140 $DbRow = $DbResult->fetch_row(); 141 $PageList = GetPageList($DbRow[0]); 142 143 $Output .= $PageList['Output']; 144 $Output .= '<div class="shoutbox">'; 145 $DbResult = $this->System->Database->query('SELECT * FROM `ForumThread` WHERE 1 ORDER BY `ID` DESC '.$PageList['SQLLimit']); 146 while($Line = $DbResult->fetch_assoc()) 147 $Output .= '<div><span style="float:right;"><strong>'.$Line['UserName'].'</strong> - ('.HumanDate($Line['Date']).')</span> <a href="?Thread='.$Line['ID'].'">'.str_replace("\n", '',$Line['Text']).'</a> </div>'; 148 $Output .= '</div>'.$PageList['Output']; 149 return($Output); 150 } 151 152 function ShowList() 153 { 154 $Output = ''; 155 156 156 $parser = new HTML_BBCodeParser2(array('filters' => array('Basic','Extended','Images','Links','Lists','Email'))); 157 // echo $parser->qparse('[youtube]http://www.youtube.com/watch?v=hwgO6p2Jh-A[/youtube][img]http://www.bbcode.org/images/lubeck_small.jpg[/img]normal [i][b]bold[/b][/i] [img]http://imageshack.com/a/img203/7462/6ctg.jpg[/img] and normal again'); 158 159 160 161 162 163 164 165 166 } else $SearchQuery = ''; 167 168 169 170 171 157 // echo $parser->qparse('[youtube]http://www.youtube.com/watch?v=hwgO6p2Jh-A[/youtube][img]http://www.bbcode.org/images/lubeck_small.jpg[/img]normal [i][b]bold[/b][/i] [img]http://imageshack.com/a/img203/7462/6ctg.jpg[/img] and normal again'); 158 159 if(array_key_exists('search', $_GET)) $_SESSION['search'] = $_GET['search']; 160 else if(!array_key_exists('search', $_SESSION)) $_SESSION['search'] = ''; 161 if(array_key_exists('search', $_GET) and ($_GET['search'] == '')) $_SESSION['search'] = ''; 162 if($_SESSION['search'] != '') 163 { 164 $SearchQuery = ' AND (`Text` LIKE "%'.$_SESSION['search'].'%")'; 165 $Output .= '<div><a href="?search=">'.sprintf(T('Disable filter "%s"'), $_SESSION['search']).'</a></div>'; 166 } else $SearchQuery = ''; 167 168 $DbResult = $this->System->Database->query('SELECT * FROM `ForumThread` WHERE ID='.($_GET['Thread']*1).' LIMIT 1'); 169 if($DbResult->num_rows > 0) 170 { 171 $Thread = $DbResult->fetch_assoc(); 172 172 $Output .= '<h3>'.$Thread['Text'].'</h3>'; 173 173 174 175 176 $PageList = GetPageList($DbRow[0]); 177 178 179 180 181 182 183 174 $DbResult = $this->System->Database->query('SELECT COUNT(*) FROM `ForumText` WHERE `Thread` = '.($_GET['Thread']*1).' '.$SearchQuery); 175 $DbRow = $DbResult->fetch_row(); 176 $PageList = GetPageList($DbRow[0]); 177 178 $Output .= $PageList['Output']; 179 $Output .= '<div class="shoutbox">'; 180 $DbResult = $this->System->Database->query('SELECT * FROM `ForumText` WHERE `Thread` = '. 181 ($_GET['Thread']*1).' '.$SearchQuery.' ORDER BY `ID` DESC '.$PageList['SQLLimit']); 182 while($Line = $DbResult->fetch_assoc()) { 183 if ($this->System->User->Id == $Line['User']) 184 184 $edit = '<a href="?Edit='.$Line['ID'].'">editovat</a>'; 185 185 else $edit = ''; … … 187 187 ')</span><strong>'.$Line['UserName'].'</strong>: '.str_replace("\n", '<br />',$parser->qparse($Line['Text'])).' </div> '; 188 188 } 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 $Output .= T('Message text').': ('.T('You can use').' <a href="http://www.bbcode.org/reference.php">'.T('BB code').'</a>)<br/>'.205 206 207 208 209 }else $Output .= ShowMessage(T('You have to be registered for adding message.'), MESSAGE_CRITICAL);210 return($Output); 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 }else $Output .= ShowMessage(T('You have to be registered for adding message.'), MESSAGE_CRITICAL);229 return($Output); 230 231 232 233 234 235 236 237 238 239 240 241 242 243 189 $Output .= '</div>'.$PageList['Output']; 190 } else $Output .= ShowMessage(T('Item not found'), MESSAGE_CRITICAL); 191 return($Output); 192 } 193 194 function ShowAddForm() 195 { 196 $Output = ''; 197 if($this->System->User->Licence(LICENCE_USER)) 198 { 199 $Output .= '<form action="?Thread='.$_GET['Thread'].'" method="post">'. 200 '<fieldset><legend>'.T('New Forum Message').'</legend>'. 201 'Uživatel: '; 202 if($this->System->User->Licence(LICENCE_USER)) $Output .= '<b>'.$this->System->User->Name.'</b><br />'; 203 else $Output .= '<input type="text" name="user" /><br />'; 204 $Output .= T('Message text').': ('.T('You can use').' <a href="http://www.bbcode.org/reference.php">'.T('BB code').'</a>)<br/>'. 205 '<textarea onkeydown="ResizeTextArea(this)" name="text" cols="80"></textarea> <br/>'. 206 '<input type="hidden" name="a" value="add2"/>'. 207 '<input type="submit" value="'.T('Send').'" /><br /></fieldset>'. 208 '</form>'; 209 } else $Output .= ShowMessage(T('You have to be registered for adding message.'), MESSAGE_CRITICAL); 210 return($Output); 211 } 212 213 function ShowAddFormThread() 214 { 215 $Output = ''; 216 if($this->System->User->Licence(LICENCE_USER)) 217 { 218 $Output .= '<form action="?" method="post">'. 219 '<fieldset><legend>'.T('New thread').'</legend>'. 220 'Uživatel: '; 221 if($this->System->User->Licence(LICENCE_USER)) $Output .= '<b>'.$this->System->User->Name.'</b><br />'; 222 else $Output .= '<input type="text" name="user" /><br />'; 223 $Output .= T('Name of thread').': <br />'. 224 '<textarea onkeydown="ResizeTextArea(this)" name="text" rows="1" cols="30"></textarea> <br/>'. 225 '<input type="hidden" name="a" value="add2"/>'. 226 '<input type="submit" value="'.T('Send').'" /><br /></fieldset>'. 227 '</form>'; 228 } else $Output .= ShowMessage(T('You have to be registered for adding message.'), MESSAGE_CRITICAL); 229 return($Output); 230 } 231 232 function AddFinish($Table = 'ForumText') 233 { 234 $Output = ''; 235 if($this->System->User->Licence(LICENCE_USER)) 236 { 237 if(array_key_exists('text', $_POST)) 238 { 239 $Text = $_POST['text']; 240 if(trim($Text) == '') $Output .= ShowMessage('Nelze vložit prázdnou zprávu.', MESSAGE_WARNING); 241 else 242 { 243 // Protection against mutiple post of same message 244 244 $Thread = ''; 245 if ($Table == 'ForumText') $Thread = 'AND `Thread` = '.$_GET['Thread']; 246 $DbResult = $this->System->Database->query('SELECT `Text` FROM `'.$Table.'` WHERE 1 '.$Thread.' AND (`User` = "'. 247 248 249 250 251 252 253 254 255 256 257 258 259 260 245 if ($Table == 'ForumText') $Thread = 'AND `Thread` = '.$_GET['Thread']; 246 $DbResult = $this->System->Database->query('SELECT `Text` FROM `'.$Table.'` WHERE 1 '.$Thread.' AND (`User` = "'. 247 $this->System->User->Id.'") ORDER BY `Date` DESC LIMIT 1'); 248 if($DbResult->num_rows > 0) 249 { 250 $DbRow = $DbResult->fetch_assoc(); 251 } else $DbRow['Text'] = ''; 252 253 if($DbRow['Text'] == $Text) $Output .= ShowMessage(T('You can\' add same message twice.'), MESSAGE_WARNING); 254 else 255 { 256 if ($Table == 'ForumText') { 257 258 $DbResult = $this->System->Database->query('SELECT * FROM `ForumThread` WHERE ID='.($_GET['Thread']*1).' LIMIT 1'); 259 if($DbResult->num_rows > 0) 260 { 261 261 $this->System->Database->query('INSERT INTO `'.$Table.'` ( `User`, `UserName` , `Text` , `Date` , `IP` , `Thread` ) '. 262 263 262 ' VALUES ('.$this->System->User->Id.', "'.$this->System->User->Name. 263 '", "'.$Text.'", NOW(), "'.GetRemoteAddress().'","'.$_GET['Thread'].'")'); 264 264 } else $Output .= ShowMessage(T('Item not found'), MESSAGE_CRITICAL); 265 265 } else 266 266 $this->System->Database->query('INSERT INTO `'.$Table.'` ( `User`, `UserName` , `Text` , `Date` , `IP`) '. 267 268 269 270 271 272 } else $Output .= ShowMessage(T('You have to specified new message.'), MESSAGE_CRITICAL); 273 274 275 276 } 277 278 279 267 ' VALUES ('.$this->System->User->Id.', "'.$this->System->User->Name. 268 '", "'.$Text.'", NOW(), "'.GetRemoteAddress().'")'); 269 $Output .= ShowMessage(T('Added.')); 270 } 271 } 272 } else $Output .= ShowMessage(T('You have to specified new message.'), MESSAGE_CRITICAL); 273 $Output .= '<br/>'; 274 } else $Output .= ShowMessage(T('You have to be registered for adding message.'), MESSAGE_CRITICAL); 275 return($Output); 276 } 277 278 function ShowRSS() 279 { 280 280 $parser = new HTML_BBCodeParser2(array('filters' => array('Basic','Extended','Images','Links','Lists','Email'))); 281 281 282 282 $Items = array(); 283 284 285 283 $TitleLength = 50; 284 mb_internal_encoding('utf-8'); 285 $DbResult = $this->Database->query('SELECT `Thread`, `ID`, UNIX_TIMESTAMP(`Date`) AS `UnixDate`, '. 286 286 '`User`, `UserName`, `Text`, ( SELECT `Text` FROM `ForumThread` '. 287 287 'WHERE `ID` = `ForumText`.`Thread`) AS `ThreadText` FROM `ForumText` ORDER BY `ID` DESC LIMIT 20'); 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 288 while($DbRow = $DbResult->fetch_assoc()) 289 { 290 $Title = mb_substr($DbRow['Text'], 0, $TitleLength); 291 if(mb_strlen($Title) == $TitleLength) $Title .= '...'; 292 $Items[] = array 293 ( 294 'Title' => $DbRow['ThreadText'].' - '.$DbRow['UserName'].': ', 295 'Link' => 'http://'.$this->System->Config['Web']['Host'].$this->System->Link('/forum/?Thread='.$DbRow['Thread']), 296 'Description' => $parser->qparse($DbRow['Text']), 297 'Time' => $DbRow['UnixDate'], 298 ); 299 } 300 $Output = GenerateRSS(array 301 ( 302 'Title' => $this->System->Config['Web']['Title'].' - '.T('Forum'), 303 'Link' => 'http://'.$this->System->Config['Web']['Host'].$this->System->Link('/forum/'), 304 'Description' => $this->System->Config['Web']['Description'], 305 305 'WebmasterEmail' => $this->System->Config['Web']['AdminEmail'], 306 306 'Items' => $Items, 307 307 )); 308 308 return($Output); 309 309 } 310 310 }
Note:
See TracChangeset
for help on using the changeset viewer.