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/News/News.php

    r815 r816  
    2020  function Start()
    2121  {
    22         $this->System->RegisterPage('news', 'PageNews');
    23         $this->System->RegisterPage('rss', 'PageRSS');
    24         $this->RegisterRSS(array('Title' => T('News'), 'Channel' => 'news',
    25           'Callback' => array('PageNews', 'ShowRSS'), 'Permission' => LICENCE_ANONYMOUS));
     22    $this->System->RegisterPage('news', 'PageNews');
     23    $this->System->RegisterPage('rss', 'PageRSS');
     24    $this->RegisterRSS(array('Title' => T('News'), 'Channel' => 'news',
     25      'Callback' => array('PageNews', 'ShowRSS'), 'Permission' => LICENCE_ANONYMOUS));
    2626  }
    2727
    2828  function ShowBox()
    2929  {
    30         $Output = '<strong>'.T('System changes').':</strong><div class="NewsBox">';
    31         $DbResult = $this->Database->query('SELECT `News`.`Time`, `User`.`Name`, `News`.`Text`,`News`.`Title`'.
    32                 ' FROM `News` JOIN `User` ON `User`.`ID` = `News`.`User` ORDER BY `Time` DESC LIMIT 10');
    33         while($DbRow = $DbResult->fetch_assoc())
    34                 $Output .= '<div><strong>'.$DbRow['Title'].' ('.HumanDate($DbRow['Time']).')</strong> <br />'.$DbRow['Text'].' ('.$DbRow['Name'].')</div>';
    35         $Output .= '<a href="'.$this->System->Link('/news/').'">'.T('All news').'</a>';
    36         $Output .= '</div>';   
    37         return($Output);
     30    $Output = '<strong>'.T('System changes').':</strong><div class="NewsBox">';
     31    $DbResult = $this->Database->query('SELECT `News`.`Time`, `User`.`Name`, `News`.`Text`,`News`.`Title`'.
     32      ' FROM `News` JOIN `User` ON `User`.`ID` = `News`.`User` ORDER BY `Time` DESC LIMIT 10');
     33    while($DbRow = $DbResult->fetch_assoc())
     34      $Output .= '<div><strong>'.$DbRow['Title'].' ('.HumanDate($DbRow['Time']).')</strong> <br />'.$DbRow['Text'].' ('.$DbRow['Name'].')</div>';
     35    $Output .= '<a href="'.$this->System->Link('/news/').'">'.T('All news').'</a>';
     36    $Output .= '</div>';
     37    return($Output);
    3838  }
    3939
     
    4141  {
    4242    $this->RSSChannels[$Channel['Channel']] = $Channel;
    43    
     43
    4444    if(is_null($Pos)) $this->RSSChannelsPos[] = $Channel['Channel'];
    4545    else {
     
    5252    $Output = '';
    5353    foreach($this->RSSChannels as $Channel)
    54                 {
    55                   if($this->System->User->Licence($Channel['Permission']))
    56                           $Output .= ' <link rel="alternate" title="'.$Channel['Title'].'" href="'.
    57                         $this->System->Link('/rss/?channel='.$Channel['Channel']).'" type="application/rss+xml" />';
    58                 }
     54    {
     55      if($this->System->User->Licence($Channel['Permission']))
     56        $Output .= ' <link rel="alternate" title="'.$Channel['Title'].'" href="'.
     57          $this->System->Link('/rss/?channel='.$Channel['Channel']).'" type="application/rss+xml" />';
     58    }
    5959    return($Output);
    6060  }
     
    6363class PageNews extends Page
    6464{
    65         function Show()
    66         {
    67                 $this->Title = T('News');
    68                 if(array_key_exists('a', $_POST)) $Action = $_POST['a'];
    69                   else if(array_key_exists('a', $_GET)) $Action = $_GET['a'];
    70                   else $Action = '';
    71                 if($Action == 'add2') $Output = $this->SaveNew();
    72                 if($Action == 'add') $Output = $this->ShowAddForm();
    73                 else $Output = $this->ShowList();
    74                 return($Output);
    75         }
     65  function Show()
     66  {
     67    $this->Title = T('News');
     68    if(array_key_exists('a', $_POST)) $Action = $_POST['a'];
     69      else if(array_key_exists('a', $_GET)) $Action = $_GET['a'];
     70      else $Action = '';
     71    if($Action == 'add2') $Output = $this->SaveNew();
     72    if($Action == 'add') $Output = $this->ShowAddForm();
     73    else $Output = $this->ShowList();
     74    return($Output);
     75  }
    7676
    77         function ShowList()
    78         {
    79                 $DbResult = $this->System->Database->query('SELECT COUNT(*) FROM `News`');
    80                 $DbRow = $DbResult->fetch_row();
    81                 $PageList = GetPageList($DbRow[0]);
    82                
    83                 $Output = '<h3>'.T('News').'</h3>'.$PageList['Output'];
    84                 if($this->System->User->Licence(LICENCE_ADMIN))
    85                         $Output .= ' <a href="?a=add">'.T('Add').'</a>';
    86                 $Output .= '<div class="shoutbox">';
    87                 $DbResult = $this->System->Database->query('SELECT `News`.`Time`, `News`.`Text`, `News`.`Title`, '.
    88                                 '`User`.`Name` AS `User` FROM `News` JOIN `User` ON `User`.`Id`=`News`.`User` ORDER BY `News`.`Time` DESC '.$PageList['SQLLimit']);
    89                 while($Line = $DbResult->fetch_assoc())
    90                         $Output .= '<div><strong>'.$Line['Title'].' ('.HumanDate($Line['Time']).')</strong><br/> '.$Line['Text'].' ('.$Line['User'].')</div>';
    91                 $Output .= '</div>'.$PageList['Output'];
    92                 return($Output);
    93         }
     77  function ShowList()
     78  {
     79    $DbResult = $this->System->Database->query('SELECT COUNT(*) FROM `News`');
     80    $DbRow = $DbResult->fetch_row();
     81    $PageList = GetPageList($DbRow[0]);
    9482
    95         function ShowAddForm()
    96         {
    97                 if($this->System->User->Licence(LICENCE_ADMIN))
    98                 {
    99                   $Output = '<form action="?" method="POST">'.
    100                           T('User').': '.$this->System->User->Name.'('.$this->System->User->Id.')<br/> '.
    101                           T('Title').': <input type="text" name="title" size="40"/><br/>'.
    102                           T('Content').': <textarea rows="8" cols="40" onkeydown="ResizeTextArea(this)" class="textedit" id="Text" name="text"></textarea><br/>'.
    103                           '<input type="hidden" name="a" value="add2"/>'.
    104                           '<input type="submit" value="'.T('Save').'"/><br/>'.
    105                           '</form>';
    106                 } else $Output = ShowMessage(T('Access denied'), MESSAGE_CRITICAL);
    107                 return($Output);
    108         }
    109        
    110         function SaveNew()
    111         {
    112                 if($this->System->User->Licence(LICENCE_ADMIN))
    113                 {
    114                   if(array_key_exists('text', $_POST) and array_key_exists('title', $_POST))
    115                   {
    116                         $querty = 'INSERT INTO `News` (`Title`, `Time` ,`User` ,`Text`) VALUES ( "'.$_POST['title'].'", NOW( ) , '.
    117                                          $this->System->User->Id.', "'.$_POST['text'].'")';
    118                           $this->System->Database->query($querty);
    119                           $Output = ShowMessage(T('News added'));
    120                           $this->System->ModuleManager->Modules['Log']->WriteLog('Vložena nová aktualita', LOG_TYPE_ADMINISTRATION);
    121                           $Output .= $this->ShowList();
    122                   } else $Output = ShowMessage(T('Data not specified'), MESSAGE_CRITICAL);
    123                 } else $Output = ShowMessage(T('Access denied'), MESSAGE_CRITICAL);
    124                 return($Output);
    125         }
     83    $Output = '<h3>'.T('News').'</h3>'.$PageList['Output'];
     84    if($this->System->User->Licence(LICENCE_ADMIN))
     85      $Output .= ' <a href="?a=add">'.T('Add').'</a>';
     86    $Output .= '<div class="shoutbox">';
     87    $DbResult = $this->System->Database->query('SELECT `News`.`Time`, `News`.`Text`, `News`.`Title`, '.
     88        '`User`.`Name` AS `User` FROM `News` JOIN `User` ON `User`.`Id`=`News`.`User` ORDER BY `News`.`Time` DESC '.$PageList['SQLLimit']);
     89    while($Line = $DbResult->fetch_assoc())
     90      $Output .= '<div><strong>'.$Line['Title'].' ('.HumanDate($Line['Time']).')</strong><br/> '.$Line['Text'].' ('.$Line['User'].')</div>';
     91    $Output .= '</div>'.$PageList['Output'];
     92    return($Output);
     93  }
    12694
    127         function ShowRSS()
    128         {
    129                 $Items = array();
     95  function ShowAddForm()
     96  {
     97    if($this->System->User->Licence(LICENCE_ADMIN))
     98    {
     99      $Output = '<form action="?" method="POST">'.
     100        T('User').': '.$this->System->User->Name.'('.$this->System->User->Id.')<br/> '.
     101        T('Title').': <input type="text" name="title" size="40"/><br/>'.
     102        T('Content').': <textarea rows="8" cols="40" onkeydown="ResizeTextArea(this)" class="textedit" id="Text" name="text"></textarea><br/>'.
     103        '<input type="hidden" name="a" value="add2"/>'.
     104        '<input type="submit" value="'.T('Save').'"/><br/>'.
     105        '</form>';
     106    } else $Output = ShowMessage(T('Access denied'), MESSAGE_CRITICAL);
     107    return($Output);
     108  }
     109
     110  function SaveNew()
     111  {
     112    if($this->System->User->Licence(LICENCE_ADMIN))
     113    {
     114      if(array_key_exists('text', $_POST) and array_key_exists('title', $_POST))
     115      {
     116        $querty = 'INSERT INTO `News` (`Title`, `Time` ,`User` ,`Text`) VALUES ( "'.$_POST['title'].'", NOW( ) , '.
     117           $this->System->User->Id.', "'.$_POST['text'].'")';
     118        $this->System->Database->query($querty);
     119        $Output = ShowMessage(T('News added'));
     120        $this->System->ModuleManager->Modules['Log']->WriteLog('Vložena nová aktualita', LOG_TYPE_ADMINISTRATION);
     121        $Output .= $this->ShowList();
     122      } else $Output = ShowMessage(T('Data not specified'), MESSAGE_CRITICAL);
     123    } else $Output = ShowMessage(T('Access denied'), MESSAGE_CRITICAL);
     124    return($Output);
     125  }
     126
     127  function ShowRSS()
     128  {
     129    $Items = array();
    130130    $DbResult = $this->Database->query('SELECT UNIX_TIMESTAMP(`News`.`Time`) AS `UnixTime`, '.
    131             '`News`.`Title`, `News`.`Time`, `User`.`Name`, `News`.`Text` '.
    132             'FROM `News` JOIN `User` ON `User`.`ID` = `News`.`User` ORDER BY `Time` DESC LIMIT 10');
    133           while($DbRow = $DbResult->fetch_assoc())
    134           {
    135            $Items[] = array
    136            (
    137              'Title' => $DbRow['Title'],
    138              'Link' =>  'http://'.$this->System->Config['Web']['Host'].$this->System->Link('/news/'),
    139              'Description' => $DbRow['Text'].' ('.$DbRow['Name'].')',
    140              'Time' => $DbRow['UnixTime'],
    141            );
    142           }
    143           $Output = GenerateRSS(array
    144           (
    145             'Title' => $this->System->Config['Web']['Title'].' - '.T('System changes'),
    146             'Link' => 'http://'.$this->System->Config['Web']['Host'].$this->System->Link('/news/'),
    147             'Description' => $this->System->Config['Web']['Description'],
    148             'WebmasterEmail' => $this->System->Config['Web']['AdminEmail'],
    149             'Items' => $Items,
    150           ));
    151           return($Output);
    152         }
     131      '`News`.`Title`, `News`.`Time`, `User`.`Name`, `News`.`Text` '.
     132      'FROM `News` JOIN `User` ON `User`.`ID` = `News`.`User` ORDER BY `Time` DESC LIMIT 10');
     133    while($DbRow = $DbResult->fetch_assoc())
     134    {
     135     $Items[] = array
     136     (
     137       'Title' => $DbRow['Title'],
     138       'Link' =>  'http://'.$this->System->Config['Web']['Host'].$this->System->Link('/news/'),
     139       'Description' => $DbRow['Text'].' ('.$DbRow['Name'].')',
     140       'Time' => $DbRow['UnixTime'],
     141     );
     142    }
     143    $Output = GenerateRSS(array
     144    (
     145      'Title' => $this->System->Config['Web']['Title'].' - '.T('System changes'),
     146      'Link' => 'http://'.$this->System->Config['Web']['Host'].$this->System->Link('/news/'),
     147      'Description' => $this->System->Config['Web']['Description'],
     148      'WebmasterEmail' => $this->System->Config['Web']['AdminEmail'],
     149      'Items' => $Items,
     150    ));
     151    return($Output);
     152  }
    153153}
Note: See TracChangeset for help on using the changeset viewer.