Ignore:
Timestamp:
Feb 22, 2015, 11:20:50 PM (9 years ago)
Author:
chronos
Message:
  • Modified: Tabs converted to spaces.
  • Modified: Remove spaces from end of lines.
  • Added: Code format script.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Modules/Forum/Forum.php

    r805 r816  
    33class ModuleForum extends AppModule
    44{
    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    
     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
    2323    if(array_key_exists('Search', $this->System->ModuleManager->Modules))
    2424      $this->System->ModuleManager->Modules['Search']->RegisterSearch('forum',
     
    2727      $this->System->ModuleManager->Modules['Search']->RegisterSearch('forumthread',
    2828      T('Name of thread forum'), array('UserName', 'Text'), '`ForumThread`', $this->System->Link('/forum/?search='));
    29                
     29
    3030    $this->System->RegisterMenuItem(array(
    3131      'Title' => T('Forum'),
     
    3535      'Icon' => '',
    3636    ), 17);
    37         }
     37  }
    3838}
    3939
    4040class PageForum extends Page
    4141{
    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'];
     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'];
    4848           else $Action = '';
    4949    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();
    5252      $Output .= $this->ShowEditForm();
    53      
     53
    5454    } else
    5555    if (array_key_exists('search', $_GET))
     
    5757    else
    5858    if (array_key_exists('Thread', $_GET)) {
    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();
     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();
    6363    } else {
    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();
     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();
    6767      $Output .= $this->ShowListThread();
    6868    }
    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    
     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
    8080    $Output .= ShowMessage(T('Text edited.'));
    8181
    82        
     82
    8383    return ($Output);
    8484  }
    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']);
     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']);
    9292      if ( $DbResult->num_rows > 0) {
    9393        $DbRow = $DbResult->fetch_assoc();
    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()
     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()
    110110  {
    111111    $parser = new HTML_BBCodeParser2(array('filters' => array('Basic','Extended','Images','Links','Lists','Email')));
    112         $Count = 20;
    113         $Output = '';
    114  
    115                 $Output .= '<div class="shoutbox">';
     112    $Count = 20;
     113    $Output = '';
     114
     115    $Output .= '<div class="shoutbox">';
    116116    $where = '`ForumText`.`Text` LIKE "%'.($_GET['search'] ).'%" OR '.
    117117    ' `ForumThread`.`Text` LIKE "%'.($_GET['search'] ).'%" OR `ForumThread`.`UserName` LIKE "%'.($_GET['search'] ).'%" OR '.
     
    119119    $join = ' JOIN `ForumThread` ON `ForumThread`.`ID` = `ForumText`.`Thread`';
    120120
    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`,'.
     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`,'.
    128128    '`ForumThread`.`Text` as `ThreadName`,`ForumText`.`Thread` FROM `ForumText` '.$join.' WHERE '.$where.' ORDER BY `ForumText`.`Date` DESC '.$PageList['SQLLimit']);
    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    
     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
    156156    $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                 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();
     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();
    172172    $Output .= '<h3>'.$Thread['Text'].'</h3>';
    173173
    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'])
     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'])
    184184        $edit = '<a href="?Edit='.$Line['ID'].'">editovat</a>';
    185185      else $edit = '';
     
    187187        ')</span><strong>'.$Line['UserName'].'</strong>: '.str_replace("\n", '<br />',$parser->qparse($Line['Text'])).'  </div> ';
    188188    }
    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
     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
    244244          $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                                                         $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                           {
     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              {
    261261                $this->System->Database->query('INSERT INTO `'.$Table.'` ( `User`, `UserName` , `Text` , `Date` , `IP` , `Thread` ) '.
    262                                                                 ' VALUES ('.$this->System->User->Id.', "'.$this->System->User->Name.
    263                                                                 '", "'.$Text.'", NOW(), "'.GetRemoteAddress().'","'.$_GET['Thread'].'")');
     262                ' VALUES ('.$this->System->User->Id.', "'.$this->System->User->Name.
     263                '", "'.$Text.'", NOW(), "'.GetRemoteAddress().'","'.$_GET['Thread'].'")');
    264264              } else $Output .= ShowMessage(T('Item not found'), MESSAGE_CRITICAL);
    265265             } else
    266266            $this->System->Database->query('INSERT INTO `'.$Table.'` ( `User`, `UserName` , `Text` , `Date` , `IP`) '.
    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         {
     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  {
    280280    $parser = new HTML_BBCodeParser2(array('filters' => array('Basic','Extended','Images','Links','Lists','Email')));
    281281
    282282    $Items = array();
    283           $TitleLength = 50;
    284           mb_internal_encoding('utf-8');
    285           $DbResult = $this->Database->query('SELECT `Thread`, `ID`, UNIX_TIMESTAMP(`Date`) AS `UnixDate`, '.
     283    $TitleLength = 50;
     284    mb_internal_encoding('utf-8');
     285    $DbResult = $this->Database->query('SELECT `Thread`, `ID`, UNIX_TIMESTAMP(`Date`) AS `UnixDate`, '.
    286286      '`User`, `UserName`, `Text`, ( SELECT `Text` FROM `ForumThread` '.
    287287      'WHERE `ID` = `ForumText`.`Thread`) AS `ThreadText` FROM `ForumText` ORDER BY `ID` DESC LIMIT 20');
    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'],
     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'],
    305305      'WebmasterEmail' => $this->System->Config['Web']['AdminEmail'],
    306306      'Items' => $Items,
    307307    ));
    308308    return($Output);
    309         }
     309  }
    310310}
Note: See TracChangeset for help on using the changeset viewer.