Name = 'Forum'; $this->Version = '1.0'; $this->Creator = 'Maron'; $this->License = 'GNU/GPL'; $this->Description = ''; $this->Dependencies = array(); } function DoStart(): void { $this->System->RegisterPage(['forum'], 'PageForum'); $this->System->ModuleManager->Modules['News']->RegisterRSS(array( 'Title' => T('Forum'), 'Channel' => 'forum', 'Callback' => array('PageForum', 'ShowRSS'), 'Permission' => LICENCE_ANONYMOUS)); if (array_key_exists('Search', $this->System->ModuleManager->Modules)) $this->System->ModuleManager->Modules['Search']->RegisterSearch('forum', T('Forum'), array('UserName', 'Text'), '`ForumText`', $this->System->Link('/forum/?search=')); if (array_key_exists('Search', $this->System->ModuleManager->Modules)) $this->System->ModuleManager->Modules['Search']->RegisterSearch('forumthread', T('Name of thread forum'), array('UserName', 'Text'), '`ForumThread`', $this->System->Link('/forum/?search=')); Core::Cast($this->System)->RegisterMenuItem(array( 'Title' => T('Forum'), 'Hint' => T('Forum about translation wow'), 'Link' => $this->System->Link('/forum/'), 'Permission' => LICENCE_ANONYMOUS, 'Icon' => '', ), 17); } function ShowBox() { $Count = 20; $Output = ''.T('Last forum posts').':'; $Output .= '
'; $Query = 'SELECT `ForumText`.`Text`, `ForumText`.`Date`, `User`.`Name` AS `UserName`, '. '`User`.`Id` AS `UserId`, `ForumText`.`Thread` '. 'FROM `ForumText` '. 'JOIN `User` ON `User`.`Id` = `ForumText`.`User` '. 'ORDER BY `Date` DESC LIMIT '.$Count; $DbResult = $this->Database->query($Query); $Output .= ''; while ($DbRow = $DbResult->fetch_assoc()) { $Output .= ''. ''. ''. ''. ''; } $Output .= '
'.T('Date').''.T('User').''.T('Post').'
'.HumanDate($DbRow['Date']).''.$DbRow['UserName'].''.ShowBBcodes(htmlspecialchars($DbRow['Text'])).'
'; return $Output; } } class PageForum extends Page { function Show(): string { $User = ModuleUser::Cast($this->System->GetModule('User'))->User; $Output = ''; $this->Title = T('Forum'); if (array_key_exists('a', $_POST)) $Action = $_POST['a']; else if (array_key_exists('a', $_GET)) $Action = $_GET['a']; else $Action = ''; if (array_key_exists('Edit', $_GET)) { if (array_key_exists('text', $_POST)) $Output .= $this->Edit(); $Output .= $this->ShowEditForm(); } else if (array_key_exists('search', $_GET)) $Output .= $this->ShowSearchForum(); else if (array_key_exists('Thread', $_GET)) { $Output .= '

'.T('Forum - Thread').'

'; if ($Action == 'add2') $Output .= $this->AddFinish(); if ($User->Licence(LICENCE_USER)) $Output .= $this->ShowAddForm(); $Output .= $this->ShowList(); } else { $Output .= '

'.T('Forum - List of Thread').'

'; if ($Action == 'add2') $Output .= $this->AddFinish('ForumThread'); if ($User->Licence(LICENCE_USER)) $Output .= $this->ShowAddFormThread(); $Output .= $this->ShowListThread(); } return $Output; } function Edit() { $User = ModuleUser::Cast($this->System->GetModule('User'))->User; $Output = ''; $this->System->Database->query('UPDATE `ForumText` SET `Text`="'.$_POST['text'].'" WHERE `User` = '.$User->Id.' AND `ID` = '.$_GET['Edit']); $Output .= ShowMessage(T('Text edited.')); return $Output; } function ShowEditForm() { $User = ModuleUser::Cast($this->System->GetModule('User'))->User; $Output = ''; if ($User->Licence(LICENCE_USER)) { $DbResult = $this->System->Database->query('SELECT * FROM `ForumText` WHERE `User` = '.$User->Id.' AND `ID` = '.$_GET['Edit']); if ( $DbResult->num_rows > 0) { $DbRow = $DbResult->fetch_assoc(); $Output .= '
'. '
'.T('Edit message').''. T('User').': '; if ($User->Licence(LICENCE_USER)) $Output .= ''.$User->Name.'
'; else $Output .= '
'; $Output .= T('Message text').': ('.T('You can use').' '.T('BB code').')
'. '
'. ''. '
'. '
'; } else $Output .= ShowMessage(T('You have to be registered for adding message.'), MESSAGE_CRITICAL); } else $Output .= ShowMessage(T('You can edit only your own message.'), MESSAGE_CRITICAL); return $Output; } function ShowSearchForum() { $Output = ''; $Output .= '
'; $where = '`ForumText`.`Text` LIKE "%'.($_GET['search'] ).'%" OR '. ' `ForumThread`.`Text` LIKE "%'.($_GET['search'] ).'%" OR `ForumThread`.`UserName` LIKE "%'.($_GET['search'] ).'%" OR '. ' `ForumText`.`UserName` LIKE "%'.($_GET['search'] ).'%"'; $join = ' JOIN `ForumThread` ON `ForumThread`.`ID` = `ForumText`.`Thread`'; $DbResult = $this->System->Database->query('SELECT COUNT(*) FROM `ForumText` '.$join.' WHERE '.$where); $DbRow = $DbResult->fetch_row(); $PageList = GetPageList($DbRow[0]); $Output .= $PageList['Output']; $DbResult = $this->System->Database->query('SELECT `ForumText`.`Text`, `ForumText`.`Date`, `ForumText`.`UserName`,'. '`ForumThread`.`Text` as `ThreadName`,`ForumText`.`Thread` FROM `ForumText` '.$join.' WHERE '.$where.' ORDER BY `ForumText`.`Date` DESC '.$PageList['SQLLimit']); while ($Line = $DbResult->fetch_assoc()) $Output .= '
'. htmlspecialchars($Line['ThreadName']).'
'.$Line['UserName']. ' ('.HumanDate($Line['Date']).'): '.ShowBBcodes(htmlspecialchars($Line['Text'])).'
'; $Output .= '
'.$PageList['Output']; return $Output; } function ShowListThread() { $Output = ''; $DbResult = $this->System->Database->query('SELECT COUNT(*) FROM `ForumThread` WHERE 1'); $DbRow = $DbResult->fetch_row(); $PageList = GetPageList($DbRow[0]); $Output .= $PageList['Output']; $Output .= '
'; $DbResult = $this->System->Database->query('SELECT * FROM `ForumThread` WHERE 1 ORDER BY `ID` DESC '.$PageList['SQLLimit']); while ($Line = $DbResult->fetch_assoc()) { $Output .= '
'.$Line['UserName']. ' - ('.HumanDate($Line['Date']).') '. str_replace("\n", '', htmlspecialchars($Line['Text'])).'
'; } $Output .= '
'.$PageList['Output']; return $Output; } function ShowList() { $User = ModuleUser::Cast($this->System->GetModule('User'))->User; $Output = ''; if (array_key_exists('search', $_GET)) $_SESSION['search'] = $_GET['search']; else if (!array_key_exists('search', $_SESSION)) $_SESSION['search'] = ''; if (array_key_exists('search', $_GET) and ($_GET['search'] == '')) $_SESSION['search'] = ''; if ($_SESSION['search'] != '') { $SearchQuery = ' AND (`Text` LIKE "%'.$_SESSION['search'].'%")'; $Output .= '
'.sprintf(T('Disable filter "%s"'), $_SESSION['search']).'
'; } else $SearchQuery = ''; $DbResult = $this->System->Database->query('SELECT * FROM `ForumThread` WHERE ID='.($_GET['Thread']*1).' LIMIT 1'); if ($DbResult->num_rows > 0) { $Thread = $DbResult->fetch_assoc(); $Output .= '

'.htmlspecialchars($Thread['Text']).'

'; $DbResult = $this->System->Database->query('SELECT COUNT(*) FROM `ForumText` WHERE `Thread` = '.($_GET['Thread']*1).' '.$SearchQuery); $DbRow = $DbResult->fetch_row(); $PageList = GetPageList($DbRow[0]); $Output .= $PageList['Output']; $Output .= '
'; $DbResult = $this->System->Database->query('SELECT * FROM `ForumText` WHERE `Thread` = '. ($_GET['Thread'] * 1).' '.$SearchQuery.' ORDER BY `ID` DESC '.$PageList['SQLLimit']); while ($Line = $DbResult->fetch_assoc()) { if ($User->Id == $Line['User']) { $edit = ''.T('edit').''; } else $edit = ''; $Text = str_replace("\n", '
', ShowBBcodes(htmlspecialchars($Line['Text']))); $Output .= '
'.$edit.' ('.HumanDate($Line['Date']). ')'.$Line['UserName'].': '.$Text.'
'; } $Output .= '
'.$PageList['Output']; } else $Output .= ShowMessage(T('Item not found'), MESSAGE_CRITICAL); return $Output; } function ShowAddForm() { $User = ModuleUser::Cast($this->System->GetModule('User'))->User; $Output = ''; if ($User->Licence(LICENCE_USER)) { $Output .= '
'. '
'.T('New Forum Message').''. T('User').': '; if ($User->Licence(LICENCE_USER)) $Output .= ''.$User->Name.'
'; else $Output .= '
'; $Output .= T('Message text').': ('.T('You can use').' '.T('BB code').')
'. '
'. ''. '
'. '
'; } else $Output .= ShowMessage(T('You have to be registered for adding message.'), MESSAGE_CRITICAL); return $Output; } function ShowAddFormThread() { $User = ModuleUser::Cast($this->System->GetModule('User'))->User; $Output = ''; if ($User->Licence(LICENCE_USER)) { $Output .= '
'. '
'.T('New thread').''.T('User').': '; if ($User->Licence(LICENCE_USER)) $Output .= ''.$User->Name.'
'; else $Output .= '
'; $Output .= T('Name of thread').':
'. '
'. ''. '
'. '
'; } else $Output .= ShowMessage(T('You have to be registered for adding message.'), MESSAGE_CRITICAL); return $Output; } function AddFinish($Table = 'ForumText') { $User = ModuleUser::Cast($this->System->GetModule('User'))->User; $Output = ''; if ($User->Licence(LICENCE_USER)) { if (array_key_exists('text', $_POST)) { $Text = $_POST['text']; if (trim($Text) == '') $Output .= ShowMessage('Nelze vložit prázdnou zprávu.', MESSAGE_WARNING); else { // Protection against mutiple post of same message $Thread = ''; if ($Table == 'ForumText') $Thread = 'AND `Thread` = '.$_GET['Thread']; $DbResult = $this->System->Database->query('SELECT `Text` FROM `'.$Table.'` WHERE 1 '.$Thread.' AND (`User` = "'. $User->Id.'") ORDER BY `Date` DESC LIMIT 1'); if ($DbResult->num_rows > 0) { $DbRow = $DbResult->fetch_assoc(); } else $DbRow['Text'] = ''; if ($DbRow['Text'] == $Text) $Output .= ShowMessage(T('You can\' add same message twice.'), MESSAGE_WARNING); else { if ($Table == 'ForumText') { $DbResult = $this->System->Database->query('SELECT * FROM `ForumThread` WHERE ID='.($_GET['Thread']*1).' LIMIT 1'); if ($DbResult->num_rows > 0) { $this->System->Database->query('INSERT INTO `'.$Table.'` ( `User`, `UserName` , `Text` , `Date` , `IP` , `Thread` ) '. ' VALUES ('.$User->Id.', "'.$User->Name. '", "'.$Text.'", NOW(), "'.GetRemoteAddress().'","'.$_GET['Thread'].'")'); } else $Output .= ShowMessage(T('Item not found'), MESSAGE_CRITICAL); } else $this->System->Database->query('INSERT INTO `'.$Table.'` ( `User`, `UserName` , `Text` , `Date` , `IP`) '. ' VALUES ('.$User->Id.', "'.$User->Name. '", "'.$Text.'", NOW(), "'.GetRemoteAddress().'")'); $Output .= ShowMessage(T('Added.')); } } } else $Output .= ShowMessage(T('You have to specified new message.'), MESSAGE_CRITICAL); $Output .= '
'; } else $Output .= ShowMessage(T('You have to be registered for adding message.'), MESSAGE_CRITICAL); return $Output; } function ShowRSS() { $Items = array(); $TitleLength = 50; mb_internal_encoding('utf-8'); $DbResult = $this->Database->query('SELECT `Thread`, `ID`, UNIX_TIMESTAMP(`Date`) AS `UnixDate`, '. '`User`, `UserName`, `Text`, ( SELECT `Text` FROM `ForumThread` '. 'WHERE `ID` = `ForumText`.`Thread`) AS `ThreadText` FROM `ForumText` ORDER BY `ID` DESC LIMIT 20'); while ($DbRow = $DbResult->fetch_assoc()) { $Title = mb_substr($DbRow['Text'], 0, $TitleLength); if (mb_strlen($Title) == $TitleLength) $Title .= '...'; $Items[] = array ( 'Title' => htmlspecialchars($DbRow['ThreadText']).' - '.$DbRow['UserName'].': ', 'Link' => 'https://'.Core::Cast($this->System)->Config['Web']['Host'].$this->System->Link('/forum/?Thread='.$DbRow['Thread']), 'Description' => ShowBBcodes(htmlspecialchars($DbRow['Text'])), 'Time' => $DbRow['UnixDate'], ); } $Output = GenerateRSS(array ( 'Title' => Core::Cast($this->System)->Config['Web']['Title'].' - '.T('Forum'), 'Link' => 'https://'.Core::Cast($this->System)->Config['Web']['Host'].$this->System->Link('/forum/'), 'Description' => Core::Cast($this->System)->Config['Web']['Description'], 'WebmasterEmail' => Core::Cast($this->System)->Config['Web']['AdminEmail'], 'Items' => $Items, )); return $Output; } }