Ignore:
Timestamp:
Apr 6, 2020, 11:17:40 PM (5 years ago)
Author:
chronos
Message:
  • Modified: Improved code format.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Modules/News/NewsPage.php

    r839 r873  
    1111  {
    1212    $this->UploadedFilesFolder = $this->System->ModuleManager->Modules['News']->UploadedFilesFolder;
    13     if(count($this->System->PathItems) > 1)
    14     {
    15       if($this->System->PathItems[1] == 'subscription') return($this->ShowSubscription());
    16         else if($this->System->PathItems[1] == 'rss') return($this->ShowRSS());
    17         else return(PAGE_NOT_FOUND);
    18     } else return($this->ShowMain());
     13    if (count($this->System->PathItems) > 1)
     14    {
     15      if ($this->System->PathItems[1] == 'subscription') return ($this->ShowSubscription());
     16        else if ($this->System->PathItems[1] == 'rss') return ($this->ShowRSS());
     17        else return (PAGE_NOT_FOUND);
     18    } else return ($this->ShowMain());
    1919  }
    2020
     
    2222  {
    2323    $Output = '';
    24     if(!$this->System->User->CheckPermission('News', 'Display', 'Item')) $Output .= 'Nemáte oprávnění';
     24    if (!$this->System->User->CheckPermission('News', 'Display', 'Item')) $Output .= 'Nemáte oprávnění';
    2525    else
    2626    {
    2727      $Category = $this->GetCategory();
    28       if(array_key_exists('id', $_GET)) $Id = $_GET['id'] * 1;
     28      if (array_key_exists('id', $_GET)) $Id = $_GET['id'] * 1;
    2929      $DbResult = $this->Database->query('SELECT `News`.*, `User`.`Name` FROM `News` '.
    3030        'LEFT JOIN `User` ON `User`.`Id`=`News`.`User` WHERE `News`.`Id`='.$Id);
    31       if($DbResult->num_rows > 0)
     31      if ($DbResult->num_rows > 0)
    3232      {
    3333        $Row = $DbResult->fetch_array();
    34         if($Row['Name'] == '') $Author = $Row['Author'];
     34        if ($Row['Name'] == '') $Author = $Row['Author'];
    3535          else $Author = $Row['Name'];
    3636        $Output .= '<div class="Panel"><div class="Title">'.$Row['Title'].' ('.HumanDate($Row['Date']).', '.$Author.')';
    37         if(($this->System->User->User['Id'] == $Row['User']) and ($this->System->User->CheckPermission('News', 'Insert', 'Group', $Category['Id'])))
     37        if (($this->System->User->User['Id'] == $Row['User']) and ($this->System->User->CheckPermission('News', 'Insert', 'Group', $Category['Id'])))
    3838        {
    3939          $Output .= '<div class="Action">';
     
    4343        }
    4444        $Output .= '</div><div class="Content">'.$this->System->ModuleManager->Modules['News']->ModifyContent($Row['Content']).'<br />';
    45         if($Row['Link'] != '') $Output .= '<br/><a href="'.$Row['Link'].'">Odkaz</a>';
    46         if($Row['Enclosure'] != '')
     45        if ($Row['Link'] != '') $Output .= '<br/><a href="'.$Row['Link'].'">Odkaz</a>';
     46        if ($Row['Enclosure'] != '')
    4747        {
    4848          $Output .= '<br />Přílohy: ';
    4949          $Enclosures = explode(';', $Row['Enclosure']);
    50           foreach($Enclosures as $Enclosure)
     50          foreach ($Enclosures as $Enclosure)
    5151          {
    52             if(file_exists($this->UploadedFilesFolder.$Enclosure))
     52            if (file_exists($this->UploadedFilesFolder.$Enclosure))
    5353              $Output .= ' <a href="'.$this->System->Link('/'.$this->UploadedFilesFolder.$Enclosure).'">'.$Enclosure.'</a>';
    5454          }
     
    5757      } else $Output .= 'Položka nenalezena.';
    5858    }
    59     return($Output);
     59    return ($Output);
    6060  }
    6161
     
    6464    $Output = '';
    6565    $Category = $this->GetCategory();
    66     if($this->System->User->CheckPermission('News', 'Insert', 'Group', $Category['Id']))
     66    if ($this->System->User->CheckPermission('News', 'Insert', 'Group', $Category['Id']))
    6767    {
    6868      $this->System->PageHeaders[] = array($this, 'GetPageHeader');
    6969      $Output = '<strong>Vložení nové aktuality:</strong><br />';
    7070      // TODO: Static reference to dynamic category item
    71       if($Category['Id'] == 2) $Output .= 'U inzerátů uvádějte co nejvíce informací ať případný zájemce ví co kupuje. Uvádějte kontaktní údaje jako Jméno, email, tel. číslo, ICQ. Dále navrženou cenu, detajlní popis předmětu nejlépe s odkazem na stránky výrobce. Pokud váš inzerát již není platný, připište do něj např. "Prodáno" pomocí editace.';
     71      if ($Category['Id'] == 2) $Output .= 'U inzerátů uvádějte co nejvíce informací ať případný zájemce ví co kupuje. Uvádějte kontaktní údaje jako Jméno, email, tel. číslo, ICQ. Dále navrženou cenu, detajlní popis předmětu nejlépe s odkazem na stránky výrobce. Pokud váš inzerát již není platný, připište do něj např. "Prodáno" pomocí editace.';
    7272      $Output .= '<form enctype="multipart/form-data" action="?action=add2" method="post">'.
    7373        'Kategorie: <select name="category">';
    7474      $DbResult = $this->Database->select('NewsCategory', '*');
    75       while($DbRow = $DbResult->fetch_array())
    76       {
    77         if($this->System->User->CheckPermission('News', 'Insert', 'Group', $DbRow['Id']))
    78         {
    79           if($DbRow['Id'] == $Category['Id']) $Selected = ' selected="1"';
     75      while ($DbRow = $DbResult->fetch_array())
     76      {
     77        if ($this->System->User->CheckPermission('News', 'Insert', 'Group', $DbRow['Id']))
     78        {
     79          if ($DbRow['Id'] == $Category['Id']) $Selected = ' selected="1"';
    8080            else $Selected = '';
    8181          $Output .= '<option value="'.$DbRow['Id'].'"'.$Selected.'>'.$DbRow['Caption'].'</option>';
     
    9393        '</form>';
    9494    } else $Output .= 'Do této kategorie nemůžete vkládat aktuality!';
    95     return($Output);
     95    return ($Output);
    9696  }
    9797
     
    101101    $RemoteAddr = GetRemoteAddress();
    102102    $Category = $this->GetCategory();
    103     if($this->System->User->CheckPermission('News', 'Insert', 'Group', $Category['Id']))
     103    if ($this->System->User->CheckPermission('News', 'Insert', 'Group', $Category['Id']))
    104104    {
    105105      // Process uploaded file
     
    107107      $EnclosureFileNames = array('enclosure1', 'enclosure2', 'enclosure3');
    108108      $Enclosures = '';
    109       foreach($EnclosureFileNames as $EnclosureName)
    110         if(array_key_exists($EnclosureName, $_FILES) and ($_FILES[$EnclosureName]['name'] != ''))
     109      foreach ($EnclosureFileNames as $EnclosureName)
     110        if (array_key_exists($EnclosureName, $_FILES) and ($_FILES[$EnclosureName]['name'] != ''))
    111111        {
    112112          $UploadedFilePath = $this->UploadedFilesFolder.basename($_FILES[$EnclosureName]['name']);
    113           if(move_uploaded_file($_FILES[$EnclosureName]['tmp_name'], $UploadedFilePath))
     113          if (move_uploaded_file($_FILES[$EnclosureName]['tmp_name'], $UploadedFilePath))
    114114          {
    115115            $Output .= 'Soubor '.basename($_FILES[$EnclosureName]['name']).' byl uložen na serveru.<br />';
     
    130130        $this->System->ModuleManager->Modules['Log']->NewRecord('News', 'Aktualita přidána', $this->Database->insert_id);
    131131    } else $Output .= 'Do této kategorie nemůžete vkládat aktuality!';
    132     return($Output);
     132    return ($Output);
    133133  }
    134134
    135135  function GetPageHeader()
    136136  {
    137     return('<script src="'.$this->System->Link('/Packages/TinyMCE/tinymce.min.js').'"></script>'.
     137    return ('<script src="'.$this->System->Link('/Packages/TinyMCE/tinymce.min.js').'"></script>'.
    138138        "<script>tinymce.init({
    139139  selector: 'textarea',
     
    156156    $Output = '';
    157157    $Category = $this->GetCategory();
    158     if($this->System->User->CheckPermission('News', 'Insert', 'Group', $Category['Id']))
     158    if ($this->System->User->CheckPermission('News', 'Insert', 'Group', $Category['Id']))
    159159    {
    160160      $DbResult = $this->Database->query('SELECT * FROM `News` WHERE `Id`='.$_GET['id']);
    161161      $Row = $DbResult->fetch_array();
    162       if(($this->System->User->User['Id'] == $Row['User']))
     162      if (($this->System->User->User['Id'] == $Row['User']))
    163163      {
    164164        $this->System->PageHeaders[] = array($this, 'GetPageHeader');
     
    174174      } else $Output .= 'Nepovolená operace!';
    175175    } else $Output .= 'Do této kategorie nemůžete vkládat aktuality!';
    176     return($Output);
     176    return ($Output);
    177177  }
    178178
     
    182182    $RemoteAddr = GetRemoteAddress();
    183183    $Category = $this->GetCategory();
    184     if($this->System->User->CheckPermission('News', 'Insert', 'Group', $Category['Id']))
     184    if ($this->System->User->CheckPermission('News', 'Insert', 'Group', $Category['Id']))
    185185    {
    186186      $_POST['id'] = $_POST['id'] * 1;
    187187      $DbResult = $this->Database->select('News', '*', '`Id`='.$_POST['id']);
    188       if($DbResult->num_rows > 0)
     188      if ($DbResult->num_rows > 0)
    189189      {
    190190        $Row = $DbResult->fetch_array();
    191         if($this->System->User->User['Id'] == $Row['User'])
     191        if ($this->System->User->User['Id'] == $Row['User'])
    192192        {
    193193          $this->Database->update('News', 'Id='.$_POST['id'], array('Title' => $_POST['title'],
     
    198198      } else $Output .= 'ID nenalezeno!';
    199199    } else $Output .= 'Do této kategorie nemůžete vkládat aktuality!';
    200     return($Output);
     200    return ($Output);
    201201  }
    202202
     
    205205    $Output = '';
    206206    $Category = $this->GetCategory();
    207     if($this->System->User->CheckPermission('News', 'Insert', 'Group', $Category['Id']))
     207    if ($this->System->User->CheckPermission('News', 'Insert', 'Group', $Category['Id']))
    208208    {
    209209      $DbResult = $this->Database->query('SELECT * FROM `News` WHERE `Id`='.$_GET['id']);
    210210      $Row = $DbResult->fetch_array();
    211       if($this->System->User->User['Id'] == $Row['User'])
     211      if ($this->System->User->User['Id'] == $Row['User'])
    212212      {
    213213        // TODO: Make upload using general File class
    214         if($Row['Enclosure'] != '')
     214        if ($Row['Enclosure'] != '')
    215215        {
    216216          $Output .= '<br />Přílohy: ';
    217217          $Enclosures = explode(';', $Row['Enclosure']);
    218           foreach($Enclosures as $Enclosure)
     218          foreach ($Enclosures as $Enclosure)
    219219          {
    220             if(file_exists($this->UploadedFilesFolder.$Enclosure)) unlink($this->UploadedFilesFolder.$Enclosure);
     220            if (file_exists($this->UploadedFilesFolder.$Enclosure)) unlink($this->UploadedFilesFolder.$Enclosure);
    221221          }
    222222        }
     
    225225      } else $Output .= 'Nemáte oprávnění.';
    226226    } else $Output .= 'Do této kategorie nemůžete vkládat aktuality!';
    227     return($Output);
     227    return ($Output);
    228228  }
    229229
     
    232232    $Output = '';
    233233    $Category = $this->GetCategory();
    234     if($this->System->User->CheckPermission('News', 'Display', 'Group', $Category['Id']))
     234    if ($this->System->User->CheckPermission('News', 'Display', 'Group', $Category['Id']))
    235235    {
    236236      $PerPage = 20;
     
    238238      $RowTotal = $DbResult->fetch_array();
    239239      $PageMax = $RowTotal[0];
    240       if(array_key_exists('page', $_GET)) $Page = $_GET['page'];
     240      if (array_key_exists('page', $_GET)) $Page = $_GET['page'];
    241241        else $Page = 0; //round($PageMax/$PerPage);
    242242      $Output .= '<strong>Seznam aktualit kategorie '.$Category['Caption'].':</strong><div style="font-size: small;">';
     
    245245      $DbResult = $this->Database->query('SELECT `News`.*, `User`.`Name` FROM `News` '.
    246246        'LEFT JOIN `User` ON `User`.`Id`=`News`.`User` WHERE `Category`='.$Category['Id'].' ORDER BY `News`.`Id` DESC LIMIT '.($Page * $PerPage).','.$PerPage);
    247       while($Row = $DbResult->fetch_array())
    248       {
    249         if($Row['Name'] == '') $Author = $Row['Author'];
     247      while ($Row = $DbResult->fetch_array())
     248      {
     249        if ($Row['Name'] == '') $Author = $Row['Author'];
    250250          else $Author = $Row['Name'];
    251251        $Output .= '<div class="Panel"><div class="Title"><a href="?action=view&amp;id='.$Row['Id'].'">'.$Row['Title'].'</a> ('.HumanDate($Row['Date']).', '.$Author.')';
    252         if(($this->System->User->User['Id'] == $Row['User']) and ($this->System->User->CheckPermission('News', 'Insert', 'Group', $Category['Id'])))
     252        if (($this->System->User->User['Id'] == $Row['User']) and ($this->System->User->CheckPermission('News', 'Insert', 'Group', $Category['Id'])))
    253253        {
    254254          $Output .= '<div class="Action">';
     
    258258        }
    259259        $Output .= '</div><div class="Content">'.$this->System->ModuleManager->Modules['News']->ModifyContent($Row['Content']).'<br />';
    260         if($Row['Link'] != '') $Output .= '<br/><a href="'.$Row['Link'].'">Odkaz</a>';
    261         if($Row['Enclosure'] != '')
     260        if ($Row['Link'] != '') $Output .= '<br/><a href="'.$Row['Link'].'">Odkaz</a>';
     261        if ($Row['Enclosure'] != '')
    262262        {
    263263          $Output .= '<br />Přílohy: ';
    264264          $Enclosures = explode(';', $Row['Enclosure']);
    265           foreach($Enclosures as $Enclosure)
     265          foreach ($Enclosures as $Enclosure)
    266266          {
    267             if(file_exists($this->UploadedFilesFolder.$Enclosure))
     267            if (file_exists($this->UploadedFilesFolder.$Enclosure))
    268268              $Output .= ' <a href="'.$this->System->Link('/'.$this->UploadedFilesFolder.$Enclosure).'">'.$Enclosure.'</a>';
    269269          }
     
    274274      $Output .= '</div>';
    275275    } else $Output .= 'Nemáte oprávnění.';
    276     return($Output);
     276    return ($Output);
    277277  }
    278278
     
    280280  {
    281281    $Category = array('Id' => 1); // Default category
    282     if(array_key_exists('category', $_GET)) $Category['Id'] = $_GET['category'] * 1;
    283     if(array_key_exists('category', $_POST)) $Category['Id'] = $_POST['category'] * 1;
    284     //if(is_null($Category)) throw new Exception('Kategorie neurčena');
     282    if (array_key_exists('category', $_GET)) $Category['Id'] = $_GET['category'] * 1;
     283    if (array_key_exists('category', $_POST)) $Category['Id'] = $_POST['category'] * 1;
     284    //if (is_null($Category)) throw new Exception('Kategorie neurčena');
    285285    else
    286286    {
    287287      $DbResult = $this->Database->select('NewsCategory', '*', '`Id`='.$Category['Id'].' ORDER BY `Sequence`');
    288       if($DbResult->num_rows > 0) $Category = $DbResult->fetch_array();
     288      if ($DbResult->num_rows > 0) $Category = $DbResult->fetch_array();
    289289        else $Category = array('Id' => 0); //throw new Exception('Kategorie nenalezena');
    290290    }
    291     return($Category);
     291    return ($Category);
    292292  }
    293293
     
    295295  {
    296296    $Output = '';
    297     if(array_key_exists('action',$_GET)) $Action = $_GET['action'];
     297    if (array_key_exists('action',$_GET)) $Action = $_GET['action'];
    298298      else $Action = '';
    299     if($Action == 'view') $Output .= $this->ShowView();
    300     else if($Action == 'add') $Output .= $this->ShowAdd();
    301     else if($Action == 'add2') $Output .= $this->ShowAdd2();
    302     else if($Action == 'edit') $Output .= $this->ShowEdit();
    303     else if($Action == 'update') $Output .= $this->ShowUpdate();
    304     else if($Action == 'del') $Output .= $this->ShowDelete();
     299    if ($Action == 'view') $Output .= $this->ShowView();
     300    else if ($Action == 'add') $Output .= $this->ShowAdd();
     301    else if ($Action == 'add2') $Output .= $this->ShowAdd2();
     302    else if ($Action == 'edit') $Output .= $this->ShowEdit();
     303    else if ($Action == 'update') $Output .= $this->ShowUpdate();
     304    else if ($Action == 'del') $Output .= $this->ShowDelete();
    305305    else $Output .= $this->ShowList();
    306     return($Output);
     306    return ($Output);
    307307  }
    308308
    309309  function ShowSubscription()
    310310  {
    311     if(array_key_exists('build', $_GET))
     311    if (array_key_exists('build', $_GET))
    312312    {
    313313      $Select = '';
    314       foreach($_POST as $Index => $Item)
    315       {
    316         if(substr($Index, 0, 8) == 'category') $Select .= '-'.substr($Index, 8);
     314      foreach ($_POST as $Index => $Item)
     315      {
     316        if (substr($Index, 0, 8) == 'category') $Select .= '-'.substr($Index, 8);
    317317      }
    318318      $Select = $this->System->Config['Web']['RootFolder'].'/aktuality/rss/?select='.substr($Select, 1);
     
    324324      $Output .= '<form action="?build=1" method="post">';
    325325      $DbResult = $this->Database->select('NewsCategory', '*', '1 ORDER BY `Caption`');
    326       while($Category = $DbResult->fetch_array())
     326      while ($Category = $DbResult->fetch_array())
    327327      {
    328328        $Output .= '<input type="checkbox" name="category'.$Category['Id'].'" />'.$Category['Caption'].'<br />';
     
    331331        '</form>';
    332332    }
    333     return($Output);
     333    return ($Output);
    334334  }
    335335
     
    349349
    350350    // Prepare WHERE condition
    351     if(array_key_exists('select', $_GET))
     351    if (array_key_exists('select', $_GET))
    352352    {
    353353      $Where = '';
    354354      $Parts = explode('-', $_GET['select']);
    355       foreach($Parts as $Part)
     355      foreach ($Parts as $Part)
    356356      {
    357357        $Where .= 'OR (`Category`='.($Part * 1).')';
     
    363363    $Categories = array();
    364364    $DbResult = $this->Database->select('NewsCategory', '*');
    365     while($Category = $DbResult->fetch_array())
     365    while ($Category = $DbResult->fetch_array())
    366366    {
    367367      $Categories[$Category['Id']] = $Category['Caption'];
     
    375375    $Index = 0;
    376376    //echo(DB_NumRows().',');
    377     while($Row = $DbResult->fetch_array())
     377    while ($Row = $DbResult->fetch_array())
    378378    {
    379379      $Row['post_text'] = StrTr($Row['post_text'], "\x8A\x8D\x8E\x9A\x9D\x9E", "\xA9\xAB\xAE\xB9\xBB\xBE");
     
    390390      //echo('category='.$ForumCategory.' AND title="'.addslashes($Title).'" AND content="'.addslashes($Content).'" AND author="'.addslashes($Author).'" AND date="'.$Date.'"');
    391391      $DbResult2 = $Database->select('news', '*', 'category='.$ForumCategory.' AND title="'.addslashes($Title).'" AND content="'.addslashes($Content).'" AND author="'.addslashes($Author).'" AND date="'.$Date.'"');
    392       if($DbResult2->num_rows == 0) //echo('.'); else echo('x');
     392      if ($DbResult2->num_rows == 0) //echo('.'); else echo('x');
    393393        $Database->insert('news', array('category' => $ForumCategory, 'title' => $Title, 'content' => $Content, 'author' => $Author, 'date' => $Date));
    394394        //echo($Date);
     
    400400    // Get news from database by selected categories
    401401    $DbResult = $this->Database->query('SELECT *, UNIX_TIMESTAMP(`Date`) AS `UnixTime` FROM `News` LEFT JOIN `User` ON `User`.`Id`=`News`.`User` WHERE '.$Where.' ORDER BY News.Date DESC LIMIT 0,'.$NewsCount);
    402     while($Row = $DbResult->fetch_assoc())
     402    while ($Row = $DbResult->fetch_assoc())
    403403    {
    404404      $EnclosuresText = '';
    405       if($Row['Enclosure'] != '')
     405      if ($Row['Enclosure'] != '')
    406406      {
    407407        $EnclosuresText .= '<br />Přílohy: ';
    408408        $Enclosures = explode(';', $Row['Enclosure']);
    409         foreach($Enclosures as $Enclosure)
    410         {
    411           if(file_exists($this->UploadedFilesFolder.$Enclosure))
     409        foreach ($Enclosures as $Enclosure)
     410        {
     411          if (file_exists($this->UploadedFilesFolder.$Enclosure))
    412412            $EnclosuresText .= ' <a href="'.$this->System->Link('/aktuality/'.$this->UploadedFilesFolder.$Enclosure).'">'.$Enclosure.'</a>';
    413413        }
    414414      }
    415       if($Row['Name'] == '') $Author = $Row['Author'];
     415      if ($Row['Name'] == '') $Author = $Row['Author'];
    416416        else $Author = $Row['Name'];
    417417      $Items[] = array(
     
    429429    $RSS->WebmasterEmail = $this->System->Config['Web']['AdminEmail'];
    430430    $RSS->Items = $Items;
    431     return($RSS->Generate());
     431    return ($RSS->Generate());
    432432  }
    433433}
Note: See TracChangeset for help on using the changeset viewer.