Ignore:
Timestamp:
Apr 7, 2020, 10:15:48 PM (5 years ago)
Author:
chronos
Message:
  • Modified: Improved code formatting.
File:
1 edited

Legend:

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

    r854 r880  
    2121      'Permission' => LICENCE_ANONYMOUS));
    2222
    23     if(array_key_exists('Search', $this->System->ModuleManager->Modules))
     23    if (array_key_exists('Search', $this->System->ModuleManager->Modules))
    2424      $this->System->ModuleManager->Modules['Search']->RegisterSearch('forum',
    2525      T('Forum'), array('UserName', 'Text'), '`ForumText`', $this->System->Link('/forum/?search='));
    26     if(array_key_exists('Search', $this->System->ModuleManager->Modules))
     26    if (array_key_exists('Search', $this->System->ModuleManager->Modules))
    2727      $this->System->ModuleManager->Modules['Search']->RegisterSearch('forumthread',
    2828      T('Name of thread forum'), array('UserName', 'Text'), '`ForumThread`',
     
    5353    $DbResult = $this->Database->query($Query);
    5454    $Output .= '<table class="MiniTable"><tr><th>'.T('Date').'</th><th>'.T('User').'</th><th>'.T('Post').'</th></tr>';
    55     while($DbRow = $DbResult->fetch_assoc())
     55    while ($DbRow = $DbResult->fetch_assoc())
    5656    {
    5757      $Output .= '<tr>'.
     
    6262    }
    6363    $Output .= '</table></div>';
    64     return($Output);
     64    return $Output;
    6565  }
    6666}
     
    7272    $Output = '';
    7373    $this->Title = T('Forum');
    74     if(array_key_exists('a', $_POST)) $Action = $_POST['a'];
    75       else if(array_key_exists('a', $_GET)) $Action = $_GET['a'];
     74    if (array_key_exists('a', $_POST)) $Action = $_POST['a'];
     75      else if (array_key_exists('a', $_GET)) $Action = $_GET['a'];
    7676       else $Action = '';
    7777    if (array_key_exists('Edit', $_GET)) {
     
    8686    if (array_key_exists('Thread', $_GET)) {
    8787      $Output .= '<h3>'.T('Forum - Thread').'</h3>';
    88       if($Action == 'add2') $Output .= $this->AddFinish();
    89       if($this->System->User->Licence(LICENCE_USER)) $Output .= $this->ShowAddForm();
     88      if ($Action == 'add2') $Output .= $this->AddFinish();
     89      if ($this->System->User->Licence(LICENCE_USER)) $Output .= $this->ShowAddForm();
    9090      $Output .= $this->ShowList();
    9191    } else {
    9292      $Output .= '<h3>'.T('Forum - List of Thread').'</h3>';
    93       if($Action == 'add2') $Output .= $this->AddFinish('ForumThread');
    94       if($this->System->User->Licence(LICENCE_USER)) $Output .= $this->ShowAddFormThread();
     93      if ($Action == 'add2') $Output .= $this->AddFinish('ForumThread');
     94      if ($this->System->User->Licence(LICENCE_USER)) $Output .= $this->ShowAddFormThread();
    9595      $Output .= $this->ShowListThread();
    9696    }
    97     return($Output);
     97    return $Output;
    9898  }
    9999
     
    104104    $DbResult = $this->System->Database->query('UPDATE `ForumText` SET `Text`="'.$_POST['text'].'" WHERE `User` = '.$this->System->User->Id.' AND `ID` = '.$_GET['Edit']);
    105105    $Output .= ShowMessage(T('Text edited.'));
    106     return ($Output);
     106    return $Output;
    107107  }
    108108
     
    110110  {
    111111    $Output = '';
    112     if($this->System->User->Licence(LICENCE_USER))
     112    if ($this->System->User->Licence(LICENCE_USER))
    113113    {
    114114      $DbResult = $this->System->Database->query('SELECT * FROM `ForumText`  WHERE `User` = '.$this->System->User->Id.' AND `ID` = '.$_GET['Edit']);
     
    118118            '<fieldset><legend>'.T('Edit message').'</legend>'.
    119119            T('User').': ';
    120         if($this->System->User->Licence(LICENCE_USER)) $Output .= '<b>'.$this->System->User->Name.'</b><br />';
     120        if ($this->System->User->Licence(LICENCE_USER)) $Output .= '<b>'.$this->System->User->Name.'</b><br />';
    121121          else $Output .= '<input type="text" name="user" /><br />';
    122122        $Output .= T('Message text').': ('.T('You can use').' <a href="http://www.bbcode.org/reference.php">'.T('BB code').'</a>)<br/>'.
     
    127127      } else $Output .= ShowMessage(T('You have to be registered for adding message.'), MESSAGE_CRITICAL);
    128128    }   else $Output .= ShowMessage(T('You can edit only your own message.'), MESSAGE_CRITICAL);
    129     return($Output);
     129    return $Output;
    130130  }
    131131
     
    150150    $DbResult = $this->System->Database->query('SELECT `ForumText`.`Text`, `ForumText`.`Date`, `ForumText`.`UserName`,'.
    151151    '`ForumThread`.`Text` as `ThreadName`,`ForumText`.`Thread` FROM `ForumText` '.$join.' WHERE '.$where.' ORDER BY `ForumText`.`Date` DESC '.$PageList['SQLLimit']);
    152     while($Line = $DbResult->fetch_assoc())
     152    while ($Line = $DbResult->fetch_assoc())
    153153      $Output .= '<div><a href="'.$this->System->Link('/forum/?Thread='.$Line['Thread']).'">'.
    154154      htmlspecialchars($Line['ThreadName']).'</a><br /><strong>'.$Line['UserName'].
    155155      '</strong> ('.HumanDate($Line['Date']).'): '.$parser->qparse(htmlspecialchars($Line['Text'])).'</div> ';
    156156    $Output .= '</div>'.$PageList['Output'];
    157     return($Output);
     157    return $Output;
    158158  }
    159159
     
    169169    $Output .= '<div class="shoutbox">';
    170170    $DbResult = $this->System->Database->query('SELECT * FROM `ForumThread` WHERE 1 ORDER BY `ID` DESC '.$PageList['SQLLimit']);
    171     while($Line = $DbResult->fetch_assoc())
     171    while ($Line = $DbResult->fetch_assoc())
    172172      $Output .= '<div><span style="float:right;"><strong>'.$Line['UserName'].
    173173    '</strong> - ('.HumanDate($Line['Date']).')</span> <a href="?Thread='.$Line['ID'].'">'.
    174174    str_replace("\n", '', htmlspecialchars($Line['Text'])).'</a></div>';
    175175    $Output .= '</div>'.$PageList['Output'];
    176     return($Output);
     176    return $Output;
    177177  }
    178178
     
    183183    $parser = new HTML_BBCodeParser2(array('filters' => array('Basic','Extended','Images','Links','Lists','Email')));
    184184
    185     if(array_key_exists('search', $_GET)) $_SESSION['search'] = $_GET['search'];
    186     else if(!array_key_exists('search', $_SESSION)) $_SESSION['search'] = '';
    187     if(array_key_exists('search', $_GET) and ($_GET['search'] == '')) $_SESSION['search'] = '';
    188     if($_SESSION['search'] != '')
     185    if (array_key_exists('search', $_GET)) $_SESSION['search'] = $_GET['search'];
     186    else if (!array_key_exists('search', $_SESSION)) $_SESSION['search'] = '';
     187    if (array_key_exists('search', $_GET) and ($_GET['search'] == '')) $_SESSION['search'] = '';
     188    if ($_SESSION['search'] != '')
    189189    {
    190190      $SearchQuery = ' AND (`Text` LIKE "%'.$_SESSION['search'].'%")';
     
    193193
    194194    $DbResult = $this->System->Database->query('SELECT * FROM `ForumThread` WHERE ID='.($_GET['Thread']*1).' LIMIT 1');
    195     if($DbResult->num_rows > 0)
     195    if ($DbResult->num_rows > 0)
    196196    {
    197197    $Thread = $DbResult->fetch_assoc();
     
    206206    $DbResult = $this->System->Database->query('SELECT * FROM `ForumText` WHERE `Thread` = '.
    207207      ($_GET['Thread']*1).' '.$SearchQuery.' ORDER BY `ID` DESC '.$PageList['SQLLimit']);
    208     while($Line = $DbResult->fetch_assoc()) {
     208    while ($Line = $DbResult->fetch_assoc()) {
    209209      if ($this->System->User->Id == $Line['User'])
    210210        $edit = '<a href="?Edit='.$Line['ID'].'">'.T('edit').'</a>';
     
    216216    $Output .= '</div>'.$PageList['Output'];
    217217    } else $Output .= ShowMessage(T('Item not found'), MESSAGE_CRITICAL);
    218     return($Output);
     218    return $Output;
    219219  }
    220220
     
    222222  {
    223223    $Output = '';
    224     if($this->System->User->Licence(LICENCE_USER))
     224    if ($this->System->User->Licence(LICENCE_USER))
    225225    {
    226226      $Output .= '<form action="?Thread='.$_GET['Thread'].'" method="post">'.
    227227        '<fieldset><legend>'.T('New Forum Message').'</legend>'.
    228228        T('User').': ';
    229       if($this->System->User->Licence(LICENCE_USER)) $Output .= '<b>'.$this->System->User->Name.'</b><br />';
     229      if ($this->System->User->Licence(LICENCE_USER)) $Output .= '<b>'.$this->System->User->Name.'</b><br />';
    230230        else $Output .= '<input type="text" name="user" /><br />';
    231231      $Output .= T('Message text').': ('.T('You can use').' <a href="http://www.bbcode.org/reference.php">'.T('BB code').'</a>)<br/>'.
     
    235235        '</form>';
    236236    } else $Output .= ShowMessage(T('You have to be registered for adding message.'), MESSAGE_CRITICAL);
    237     return($Output);
     237    return $Output;
    238238  }
    239239
     
    241241  {
    242242    $Output = '';
    243     if($this->System->User->Licence(LICENCE_USER))
     243    if ($this->System->User->Licence(LICENCE_USER))
    244244    {
    245245        $Output .= '<form action="?" method="post">'.
    246246            '<fieldset><legend>'.T('New thread').'</legend>'.
    247247            T('User').': ';
    248         if($this->System->User->Licence(LICENCE_USER)) $Output .= '<b>'.$this->System->User->Name.'</b><br />';
     248        if ($this->System->User->Licence(LICENCE_USER)) $Output .= '<b>'.$this->System->User->Name.'</b><br />';
    249249        else $Output .= '<input type="text" name="user" /><br />';
    250250      $Output .= T('Name of thread').': <br />'.
     
    254254      '</form>';
    255255    } else $Output .= ShowMessage(T('You have to be registered for adding message.'), MESSAGE_CRITICAL);
    256     return($Output);
     256    return $Output;
    257257  }
    258258
     
    260260  {
    261261    $Output = '';
    262     if($this->System->User->Licence(LICENCE_USER))
    263     {
    264       if(array_key_exists('text', $_POST))
     262    if ($this->System->User->Licence(LICENCE_USER))
     263    {
     264      if (array_key_exists('text', $_POST))
    265265      {
    266266        $Text = $_POST['text'];
    267         if(trim($Text) == '') $Output .= ShowMessage('Nelze vložit prázdnou zprávu.', MESSAGE_WARNING);
     267        if (trim($Text) == '') $Output .= ShowMessage('Nelze vložit prázdnou zprávu.', MESSAGE_WARNING);
    268268        else
    269269        {
     
    273273          $DbResult = $this->System->Database->query('SELECT `Text` FROM `'.$Table.'` WHERE 1 '.$Thread.' AND (`User` = "'.
    274274              $this->System->User->Id.'") ORDER BY `Date` DESC LIMIT 1');
    275           if($DbResult->num_rows > 0)
     275          if ($DbResult->num_rows > 0)
    276276          {
    277277            $DbRow = $DbResult->fetch_assoc();
    278278          } else $DbRow['Text'] = '';
    279279
    280           if($DbRow['Text'] == $Text) $Output .= ShowMessage(T('You can\' add same message twice.'), MESSAGE_WARNING);
     280          if ($DbRow['Text'] == $Text) $Output .= ShowMessage(T('You can\' add same message twice.'), MESSAGE_WARNING);
    281281          else
    282282          {
     
    284284
    285285              $DbResult = $this->System->Database->query('SELECT * FROM `ForumThread` WHERE ID='.($_GET['Thread']*1).' LIMIT 1');
    286               if($DbResult->num_rows > 0)
     286              if ($DbResult->num_rows > 0)
    287287              {
    288288                $this->System->Database->query('INSERT INTO `'.$Table.'` ( `User`, `UserName` , `Text` , `Date` , `IP` , `Thread` ) '.
     
    300300      $Output .= '<br/>';
    301301    } else $Output .= ShowMessage(T('You have to be registered for adding message.'), MESSAGE_CRITICAL);
    302     return($Output);
     302    return $Output;
    303303  }
    304304
     
    313313      '`User`, `UserName`, `Text`, ( SELECT `Text` FROM `ForumThread` '.
    314314      'WHERE `ID` = `ForumText`.`Thread`) AS `ThreadText` FROM `ForumText` ORDER BY `ID` DESC LIMIT 20');
    315     while($DbRow = $DbResult->fetch_assoc())
     315    while ($DbRow = $DbResult->fetch_assoc())
    316316    {
    317317      $Title = mb_substr($DbRow['Text'], 0, $TitleLength);
    318       if(mb_strlen($Title) == $TitleLength) $Title .= '...';
     318      if (mb_strlen($Title) == $TitleLength) $Title .= '...';
    319319      $Items[] = array
    320320      (
     
    333333      'Items' => $Items,
    334334    ));
    335     return($Output);
     335    return $Output;
    336336  }
    337337}
Note: See TracChangeset for help on using the changeset viewer.