Changeset 816 for trunk/Modules/ShoutBox/ShoutBox.php
- Timestamp:
- Feb 22, 2015, 11:20:50 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Modules/ShoutBox/ShoutBox.php
r815 r816 16 16 function Start() 17 17 { 18 19 20 21 18 $this->System->RegisterPage('shoutbox', 'PageShoutBox'); 19 $this->System->ModuleManager->Modules['News']->RegisterRSS(array( 20 'Title' => T('Shoutbox'), 'Channel' => 'shoutbox', 'Callback' => array('PageShoutBox', 'ShowRSS'), 21 'Permission' => LICENCE_ANONYMOUS)); 22 22 if(array_key_exists('Search', $this->System->ModuleManager->Modules)) 23 23 $this->System->ModuleManager->Modules['Search']->RegisterSearch('shoutbox', … … 27 27 function ShowBox() 28 28 { 29 30 31 32 33 34 35 36 37 38 29 $Output = '<strong><a href="'.$this->System->Link('/shoutbox/').'">'.T('Shoutbox').':</a></strong>'; 30 31 if($this->System->User->Licence(LICENCE_USER)) 32 $Output .= ' <a href="'.$this->System->Link('/shoutbox/?a=add').'">'.T('Add').'</a>'; 33 $Output .= '<div class="box"><table>'; 34 $DbResult = $this->Database->query('SELECT * FROM `ShoutBox` ORDER BY `ID` DESC LIMIT 30'); 35 while($Line = $DbResult->fetch_assoc()) 36 $Output .= '<tr><td><strong>'.$Line['UserName'].'</strong>: '.MakeActiveLinks($Line['Text']).'</td></tr>'; 37 $Output .= '</table></div>'; 38 return($Output); 39 39 } 40 40 } … … 42 42 class PageShoutBox extends Page 43 43 { 44 45 46 47 48 49 50 51 52 53 54 44 function Show() 45 { 46 $this->Title = T('Shoutbox'); 47 if(array_key_exists('a', $_POST)) $Action = $_POST['a']; 48 else if(array_key_exists('a', $_GET)) $Action = $_GET['a']; 49 else $Action = ''; 50 if($Action == 'add2') $Output = $this->AddFinish(); 51 if($Action == 'add') $Output = $this->ShowAddForm(); 52 else $Output = $this->ShowList(); 53 return($Output); 54 } 55 55 56 57 58 59 60 61 62 63 64 65 66 56 function ShowList() 57 { 58 $Output = ''; 59 if(array_key_exists('search', $_GET)) $_SESSION['search'] = $_GET['search']; 60 else if(!array_key_exists('search', $_SESSION)) $_SESSION['search'] = ''; 61 if(array_key_exists('search', $_GET) and ($_GET['search'] == '')) $_SESSION['search'] = ''; 62 if($_SESSION['search'] != '') 63 { 64 $SearchQuery = ' AND (`Text` LIKE "%'.$_SESSION['search'].'%")'; 65 $Output .= '<div><a href="?search=">'.sprintf(T('Disable filter "%s"'), $_SESSION['search']).'</a></div>'; 66 } else $SearchQuery = ''; 67 67 68 69 70 $PageList = GetPageList($DbRow[0]); 68 $DbResult = $this->System->Database->query('SELECT COUNT(*) FROM `ShoutBox` WHERE 1'.$SearchQuery); 69 $DbRow = $DbResult->fetch_row(); 70 $PageList = GetPageList($DbRow[0]); 71 71 72 73 74 75 76 77 78 79 80 81 72 $Output .= '<h3>'.T('Shoutbox').'</h3>'.$PageList['Output']; 73 if($this->System->User->Licence(LICENCE_USER)) 74 $Output .= ' <a href="'.$this->System->Link('/shoutbox/?a=add').'">'.T('Add').'</a>'; 75 $Output .= '<div class="shoutbox">'; 76 $DbResult = $this->System->Database->query('SELECT * FROM `ShoutBox` WHERE 1'.$SearchQuery.' ORDER BY `ID` DESC '.$PageList['SQLLimit']); 77 while($Line = $DbResult->fetch_assoc()) 78 $Output .= '<div><strong>'.$Line['UserName'].'</strong>: '.MakeActiveLinks($Line['Text']).'</div>'; 79 $Output .= '</div>'.$PageList['Output']; 80 return($Output); 81 } 82 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 }else $Output .= ShowMessage('Pro vkládaní zpráv musíte byt registrováni.', MESSAGE_CRITICAL);99 100 101 83 function ShowAddForm() 84 { 85 $Output = ''; 86 if($this->System->User->Licence(LICENCE_USER)) 87 { 88 $Output .= '<form action="?" method="post">'. 89 '<fieldset><legend>'.T('New message').'</legend>'. 90 'Uživatel: '; 91 if($this->System->User->Licence(LICENCE_USER)) $Output .= '<b>'.$this->System->User->Name.'</b><br />'; 92 else $Output .= '<input type="text" name="user" /><br />'; 93 $Output .= 'Text zprávy: <br/>'. 94 '<textarea onkeydown="ResizeTextArea(this)" name="text" cols="40"></textarea> <br/>'. 95 '<input type="hidden" name="a" value="add2"/>'. 96 '<input type="submit" value="Odeslat" /><br /></fieldset>'. 97 '</form>'; 98 } else $Output .= ShowMessage('Pro vkládaní zpráv musíte byt registrováni.', MESSAGE_CRITICAL); 99 $Output .= $this->ShowList(); 100 return($Output); 101 } 102 102 103 function AddFinish() 104 { 105 $Output = ''; 106 if($this->System->User->Licence(LICENCE_USER)) 107 { 108 if(array_key_exists('text', $_POST)) 109 { 110 $Text = $_POST['text']; 111 if(trim($Text) == '') $Output .= ShowMessage('Nelze vložit prázdnou zprávu.', MESSAGE_WARNING); 112 else 113 { 114 // Protection against mutiple post of same message 115 $DbResult = $this->System->Database->query('SELECT `Text` FROM `ShoutBox` WHERE (`User` = "'. 116 $this->System->User->Id.'") ORDER BY `Date` DESC LIMIT 1'); 117 if($DbResult->num_rows > 0) 118 { 119 $DbRow = $DbResult->fetch_assoc(); 120 } else $DbRow['Text'] = ''; 121 122 if($DbRow['Text'] == $Text) $Output .= ShowMessage('Nelze vložit stejnou zprávu vícekrát za sebou.', MESSAGE_WARNING); 123 else 124 { 125 $this->System->Database->query('INSERT INTO `ShoutBox` ( `User`, `UserName` , `Text` , `Date` , `IP` ) '. 126 ' VALUES ('.$this->System->User->Id.', "'.$this->System->User->Name. 127 '", "'.$Text.'", NOW(), "'.GetRemoteAddress().'")'); 128 $Output .= ShowMessage('Zpráva vložena.'); 129 } 130 } 131 } else $Output .= ShowMessage('Nezadán text pro novou zprávu.', MESSAGE_CRITICAL); 132 $Output .= '<br/>'; 133 } else $Output .= ShowMessage('Pro vkládaní zpráv musíte byt registrováni.', MESSAGE_CRITICAL); 134 $Output .= $this->ShowList(); 135 return($Output); 136 } 103 function AddFinish() 104 { 105 $Output = ''; 106 if($this->System->User->Licence(LICENCE_USER)) 107 { 108 if(array_key_exists('text', $_POST)) 109 { 110 $Text = $_POST['text']; 111 if(trim($Text) == '') $Output .= ShowMessage('Nelze vložit prázdnou zprávu.', MESSAGE_WARNING); 112 else 113 { 114 // Protection against mutiple post of same message 115 $DbResult = $this->System->Database->query('SELECT `Text` FROM `ShoutBox` WHERE (`User` = "'. 116 $this->System->User->Id.'") ORDER BY `Date` DESC LIMIT 1'); 117 if($DbResult->num_rows > 0) 118 { 119 $DbRow = $DbResult->fetch_assoc(); 120 } else $DbRow['Text'] = ''; 137 121 138 function ShowRSS() 139 { 140 $Items = array(); 141 $TitleLength = 50; 142 mb_internal_encoding('utf-8'); 143 $DbResult = $this->Database->query('SELECT UNIX_TIMESTAMP(`Date`) AS `UnixDate`, `User`, `UserName`, `Text` FROM `ShoutBox` ORDER BY `ID` DESC LIMIT 20'); 144 while($DbRow = $DbResult->fetch_assoc()) 145 { 146 $Title = mb_substr($DbRow['Text'], 0, $TitleLength); 147 if(mb_strlen($Title) == $TitleLength) $Title .= '...'; 148 $Items[] = array 149 ( 150 'Title' => $DbRow['UserName'].': '.$Title, 151 'Link' => 'http://'.$this->System->Config['Web']['Host'].$this->System->Link('/shoutbox/'), 152 'Description' => $DbRow['Text'], 153 'Time' => $DbRow['UnixDate'], 154 ); 155 } 156 $Output = GenerateRSS(array 122 if($DbRow['Text'] == $Text) $Output .= ShowMessage('Nelze vložit stejnou zprávu vícekrát za sebou.', MESSAGE_WARNING); 123 else 124 { 125 $this->System->Database->query('INSERT INTO `ShoutBox` ( `User`, `UserName` , `Text` , `Date` , `IP` ) '. 126 ' VALUES ('.$this->System->User->Id.', "'.$this->System->User->Name. 127 '", "'.$Text.'", NOW(), "'.GetRemoteAddress().'")'); 128 $Output .= ShowMessage('Zpráva vložena.'); 129 } 130 } 131 } else $Output .= ShowMessage('Nezadán text pro novou zprávu.', MESSAGE_CRITICAL); 132 $Output .= '<br/>'; 133 } else $Output .= ShowMessage('Pro vkládaní zpráv musíte byt registrováni.', MESSAGE_CRITICAL); 134 $Output .= $this->ShowList(); 135 return($Output); 136 } 137 138 function ShowRSS() 139 { 140 $Items = array(); 141 $TitleLength = 50; 142 mb_internal_encoding('utf-8'); 143 $DbResult = $this->Database->query('SELECT UNIX_TIMESTAMP(`Date`) AS `UnixDate`, `User`, `UserName`, `Text` FROM `ShoutBox` ORDER BY `ID` DESC LIMIT 20'); 144 while($DbRow = $DbResult->fetch_assoc()) 145 { 146 $Title = mb_substr($DbRow['Text'], 0, $TitleLength); 147 if(mb_strlen($Title) == $TitleLength) $Title .= '...'; 148 $Items[] = array 149 ( 150 'Title' => $DbRow['UserName'].': '.$Title, 151 'Link' => 'http://'.$this->System->Config['Web']['Host'].$this->System->Link('/shoutbox/'), 152 'Description' => $DbRow['Text'], 153 'Time' => $DbRow['UnixDate'], 154 ); 155 } 156 $Output = GenerateRSS(array 157 157 ( 158 158 'Title' => $this->System->Config['Web']['Title'].' - '.T('Shoutbox'), … … 163 163 )); 164 164 return($Output); 165 165 } 166 166 }
Note:
See TracChangeset
for help on using the changeset viewer.