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

Legend:

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

    r790 r873  
    55function CategoryItemCompare($Item1, $Item2)
    66{
    7   if ($Item1['Index'] == $Item2['Index']) return(0);
     7  if ($Item1['Index'] == $Item2['Index']) return (0);
    88  return ($Item1['Index'] > $Item2['Index']) ? -1 : 1;
    99}
     
    8181    ));
    8282
    83     if($this->System->ModuleManager->ModulePresent('Search'))
     83    if ($this->System->ModuleManager->ModulePresent('Search'))
    8484    {
    8585      $this->System->ModuleManager->Modules['Search']->RegisterSearch('Novinky', 'News', array('Title', 'Content'));
     
    9595    $Output = '<div class="NewsPanel"><div class="Title">'.$Row['Caption'];
    9696    $Output .= '<div class="Action"><a href="aktuality/?category='.$Category.'">Zobrazit</a>';
    97     if($this->System->User->CheckPermission('News', 'Insert', 'Group', $Category))
     97    if ($this->System->User->CheckPermission('News', 'Insert', 'Group', $Category))
    9898      $Output .= ' <a href="aktuality/?action=add&amp;category='.$Category.'">Přidat</a>';
    9999    $Output .= '</div></div><div class="Content">';
     
    102102    $Index = 0;
    103103    $FontSize = 12;
    104     if($DbResult->num_rows > 0)
     104    if ($DbResult->num_rows > 0)
    105105    {
    106106      $Output .= '<table class="NewsTable">';
    107       while($Row = $DbResult->fetch_array())
    108       {
    109         if($Row['Name'] == '') $Author = $Row['Author'];
     107      while ($Row = $DbResult->fetch_array())
     108      {
     109        if ($Row['Name'] == '') $Author = $Row['Author'];
    110110          else $Author = $Row['Name'];
    111111        $Output .= '<tr><td onclick="window.location=\'aktuality/?action=view&amp;id='.$Row['Id'].
     
    114114          '<td align="right" style="font-size: '.$FontSize.'pt">'.$Author.' ('.HumanDate($Row['Date']).')</td></tr></table>';
    115115        $Output .= '<div id="new'.$Category.$Index.'" class="NewsTableItem">'.$this->ModifyContent($Row['Content']);
    116         if($Row['Link'] != '') $Output .= '<br/><a href="'.$Row['Link'].'">Odkaz</a>';
    117 
    118         if($Row['Enclosure'] != '')
     116        if ($Row['Link'] != '') $Output .= '<br/><a href="'.$Row['Link'].'">Odkaz</a>';
     117
     118        if ($Row['Enclosure'] != '')
    119119        {
    120120          $Output .= '<br />Přílohy: ';
    121121          $Enclosures = explode(';', $Row['Enclosure']);
    122           foreach($Enclosures as $Enclosure)
     122          foreach ($Enclosures as $Enclosure)
    123123          {
    124             if(file_exists($this->UploadedFilesFolder.$Enclosure))
     124            if (file_exists($this->UploadedFilesFolder.$Enclosure))
    125125              $Output .= ' <a href="'.$this->UploadedFilesFolder.$Enclosure.'">'.$Enclosure.'</a>';
    126126          }
     
    133133    }
    134134    $Output .= '</div></div>';
    135     return($Output);
     135    return ($Output);
    136136  }
    137137
     
    142142    $I = 1;
    143143    $DbResult = $this->Database->select('NewsCategory', '*', '1 ORDER BY Sequence');
    144     while($NewsCategory = $DbResult->fetch_array())
     144    while ($NewsCategory = $DbResult->fetch_array())
    145145    {
    146146      $this->NewsSetting[] = array('CategoryId' => $NewsCategory['Id'], 'Index' => $I, 'Enabled' => 1,
     
    149149    }
    150150    // Merge defaults with user setting
    151     if(array_key_exists('NewsSetting', $_COOKIE))
     151    if (array_key_exists('NewsSetting', $_COOKIE))
    152152    {
    153153      $NewsSettingCookie = unserialize($_COOKIE['NewsSetting']);
    154       foreach($this->NewsSetting as $Index => $this->NewSetting)
    155       {
    156         if(array_key_exists($Index, $NewsSettingCookie))
     154      foreach ($this->NewsSetting as $Index => $this->NewSetting)
     155      {
     156        if (array_key_exists($Index, $NewsSettingCookie))
    157157          $this->NewsSetting[$Index] = array_merge($this->NewSetting, $NewsSettingCookie[$Index]);
    158158      }
     
    166166    $this->LoadSettingsFromCookies();
    167167
    168     if(array_key_exists('Action', $_GET))
     168    if (array_key_exists('Action', $_GET))
    169169    {
    170170      // Show news customize menu
    171       if($_GET['Action'] == 'CustomizeNews')
     171      if ($_GET['Action'] == 'CustomizeNews')
    172172      {
    173173        $Output .= $this->ShowCustomizeMenu();
     
    179179    $ColumnCount = 2;
    180180    $Output .= '<table style="width: 100%"><tr>';
    181     for($Column = 1; $Column <= $ColumnCount; $Column++)
     181    for ($Column = 1; $Column <= $ColumnCount; $Column++)
    182182    {
    183183      $Output .= '<td style="vertical-align: top; width: '.round(100 / $ColumnCount).'%;">';
    184       foreach($this->NewsSetting as $SettingItem)
    185         if(($SettingItem['Enabled'] == 1) and ($SettingItem['Group'] == $Column))
     184      foreach ($this->NewsSetting as $SettingItem)
     185        if (($SettingItem['Enabled'] == 1) and ($SettingItem['Group'] == $Column))
    186186          $Output .= $this->ShowNews($SettingItem['CategoryId'], $SettingItem['ItemCount'], $SettingItem['DaysAgo']);
    187187      $Output .= '</td>';
     
    191191    $Output .= '<a href="aktuality/subscription"><img class="RSSIcon" src="images/rss20.png" alt="Aktuality přes RSS" /></a>  <a href="aktuality/subscription">Automatické sledování novinek</a>';
    192192    $Output .= '</div>';
    193     return($Output);
     193    return ($Output);
    194194  }
    195195
     
    200200    $Output .= '<tr><th>Kategorie</th><th>Pozice</th><th>Zobrazit</th><th>Max. počet</th><th>Posledních dnů</th><th>Sloupec</th></tr>';
    201201    $I = 0;
    202     foreach($this->NewsSetting as $SettingItem)
     202    foreach ($this->NewsSetting as $SettingItem)
    203203    {
    204204      $DbResult = $this->Database->select('NewsCategory', '*', 'Id='.$SettingItem['CategoryId']);
    205205      $NewsCategory = $DbResult->fetch_array();
    206206      $Output .= '<tr><td>'.$NewsCategory['Caption'].'</td><td align="center"><input type="text" size="2" name="NewsCategoryIndex'.$I.'" value="'.$SettingItem['Index'].'" /></td><td align="center"><input type="checkbox" name="NewsCategoryEnabled'.$I.'"';
    207       if($SettingItem['Enabled'] == 1) $Output .= ' checked="checked"';
     207      if ($SettingItem['Enabled'] == 1) $Output .= ' checked="checked"';
    208208      $Output .= ' /></td>'.
    209209      '<td align="center"><input type="text" size="2" name="NewsCategoryCount'.$I.'" value="'.$SettingItem['ItemCount'].'" />'.
     
    214214    }
    215215    $Output .= '</table><input type="hidden" name="NewsCategoryCount" value="'.count($this->NewsSetting).'" /><input type="submit" value="Uložit" /></form></td></tr></table><br>';
    216     return($Output);
     216    return ($Output);
    217217  }
    218218
     
    221221    $Checkbox = array('' => 0, 'on' => 1);
    222222    $Setting = array();
    223     for($I = 0; $I < $_POST['NewsCategoryCount']; $I++)
    224     {
    225       if(($_POST['NewsCategoryDaysAgo'.$I] * 1) < 0) $_POST['NewsCategoryIndex'.$I] = 0;
    226       if(($_POST['NewsCategoryCount'.$I] * 1) < 0) $_POST['NewsCategoryCount'.$I] = 0;
    227       if(($_POST['NewsColumn'.$I] * 1) < 1) $_POST['NewsColumn'.$I] = 1;
    228       if(!array_key_exists('NewsCategoryEnabled'.$I, $_POST)) $_POST['NewsCategoryEnabled'.$I] = '';
     223    for ($I = 0; $I < $_POST['NewsCategoryCount']; $I++)
     224    {
     225      if (($_POST['NewsCategoryDaysAgo'.$I] * 1) < 0) $_POST['NewsCategoryIndex'.$I] = 0;
     226      if (($_POST['NewsCategoryCount'.$I] * 1) < 0) $_POST['NewsCategoryCount'.$I] = 0;
     227      if (($_POST['NewsColumn'.$I] * 1) < 1) $_POST['NewsColumn'.$I] = 1;
     228      if (!array_key_exists('NewsCategoryEnabled'.$I, $_POST)) $_POST['NewsCategoryEnabled'.$I] = '';
    229229      $Setting[] = array('CategoryId' => $_POST['NewsCategoryId'.$I], 'Enabled' => $Checkbox[$_POST['NewsCategoryEnabled'.$I]], 'ItemCount' => ($_POST['NewsCategoryCount'.$I]*1), 'DaysAgo' => ($_POST['NewsCategoryDaysAgo'.$I]*1), 'Index' => ($_POST['NewsCategoryIndex'.$I]*1),
    230230      'Group' => $_POST['NewsColumn'.$I]);
     
    234234    $Setting = array_reverse($Setting);
    235235    // Normalize indexes
    236     foreach($Setting as $Index => $Item)
     236    foreach ($Setting as $Index => $Item)
    237237      $Setting[$Index]['Index'] = $Index + 1;
    238238
     
    248248    // Make HTML link from URL
    249249    $I = 0;
    250     while(strpos($Content, 'http://') !== false)
     250    while (strpos($Content, 'http://') !== false)
    251251    {
    252252      $I = strpos($Content, 'http://');
    253       if(($I > 0) and ($Content{$I - 1} != '"'))
     253      if (($I > 0) and ($Content{$I - 1} != '"'))
    254254      {
    255255        $Result .= substr($Content, 0, $I);
    256256        $Content = substr($Content, $I);
    257         if(strpos($Content, ' ') !== false)
     257        if (strpos($Content, ' ') !== false)
    258258          $URL = substr($Content, 0, strpos($Content, ' '));
    259259        else $URL = substr($Content, 0);
     
    267267    }
    268268    $Result .= $Content;
    269     return($Result);
     269    return ($Result);
    270270  }
    271271}
Note: See TracChangeset for help on using the changeset viewer.