Changeset 828 for trunk/Modules


Ignore:
Timestamp:
Mar 20, 2015, 10:22:50 PM (10 years ago)
Author:
chronos
Message:
  • Added: Single news items can be now shown as separate page. So they can cached by search engines also with date information. Also they can be accessed directly from News RSS channel.
File:
1 edited

Legend:

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

    r816 r828  
    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`'.
     30    $Output = '<strong><a href="'.$this->System->Link('/news/').'">'.T('News').':</a></strong><div class="NewsBox">';
     31    $DbResult = $this->Database->query('SELECT `News`.`Time`, `User`.`Name`, `News`.`Text`,`News`.`Title`, `News`.`Id` '.
    3232      ' FROM `News` JOIN `User` ON `User`.`ID` = `News`.`User` ORDER BY `Time` DESC LIMIT 10');
    3333    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>';
     34    {
     35      $Output .= '<h4><a href="'.$this->System->Link('/news/?a=item&amp;i='.$DbRow['Id']).'">'.$DbRow['Title'].'</a> ('.HumanDate($DbRow['Time']).')</h4>'.
     36        ' <div>'.$DbRow['Text'].' ('.$DbRow['Name'].')</div>';
     37    }
    3638    $Output .= '</div>';
    3739    return($Output);
     
    7072      else $Action = '';
    7173    if($Action == 'add2') $Output = $this->SaveNew();
    72     if($Action == 'add') $Output = $this->ShowAddForm();
     74    else if($Action == 'add') $Output = $this->ShowAddForm();
     75    else if($Action == 'item') $Output = $this->ShowItem();
    7376    else $Output = $this->ShowList();
    7477    return($Output);
     
    8588      $Output .= ' <a href="?a=add">'.T('Add').'</a>';
    8689    $Output .= '<div class="shoutbox">';
    87     $DbResult = $this->System->Database->query('SELECT `News`.`Time`, `News`.`Text`, `News`.`Title`, '.
     90    $DbResult = $this->System->Database->query('SELECT `News`.`Time`, `News`.`Text`, `News`.`Title`, `News`.`Id`, '.
    8891        '`User`.`Name` AS `User` FROM `News` JOIN `User` ON `User`.`Id`=`News`.`User` ORDER BY `News`.`Time` DESC '.$PageList['SQLLimit']);
    8992    while($Line = $DbResult->fetch_assoc())
    90       $Output .= '<div><strong>'.$Line['Title'].' ('.HumanDate($Line['Time']).')</strong><br/> '.$Line['Text'].' ('.$Line['User'].')</div>';
     93    {
     94      $Output .= '<h4><a href="?a=item&amp;i='.$Line['Id'].'">'.$Line['Title'].'</a> ('.HumanDate($Line['Time']).')</h4><div>'.$Line['Text'].' ('.$Line['User'].')</div>';
     95    }
    9196    $Output .= '</div>'.$PageList['Output'];
     97    return($Output);
     98  }
     99
     100  function ShowItem()
     101  {
     102    if(array_key_exists('i', $_GET))
     103    {
     104      $Output = '<h3>'.T('News').'</h3>';
     105      $DbResult = $this->System->Database->query('SELECT `News`.`Time`, `News`.`Text`, `News`.`Title`, `News`.`Id`, '.
     106        '`User`.`Name` AS `User` FROM `News` JOIN `User` ON `User`.`Id`=`News`.`User` WHERE `News`.`Id` = '.($_GET['i'] * 1));
     107      if($DbResult->num_rows == 1)
     108      {
     109        $Line = $DbResult->fetch_assoc();
     110        $Output .= '<h4>'.$Line['Title'].' ('.HumanDate($Line['Time']).')</h4><div>'.$Line['Text'].' ('.$Line['User'].')</div>';
     111      } else $Output = ShowMessage(T('Item not found'), MESSAGE_CRITICAL);
     112    } else $Output = ShowMessage(T('Item not found'), MESSAGE_CRITICAL);
     113    $Output .= '<br/><a href="'.$this->System->Link('/news/').'">'.T('All news').'</a>';
    92114    return($Output);
    93115  }
     
    129151    $Items = array();
    130152    $DbResult = $this->Database->query('SELECT UNIX_TIMESTAMP(`News`.`Time`) AS `UnixTime`, '.
    131       '`News`.`Title`, `News`.`Time`, `User`.`Name`, `News`.`Text` '.
     153      '`News`.`Title`, `News`.`Time`, `User`.`Name`, `News`.`Text`, `News`.`Id` '.
    132154      'FROM `News` JOIN `User` ON `User`.`ID` = `News`.`User` ORDER BY `Time` DESC LIMIT 10');
    133155    while($DbRow = $DbResult->fetch_assoc())
     
    136158     (
    137159       'Title' => $DbRow['Title'],
    138        'Link' =>  'http://'.$this->System->Config['Web']['Host'].$this->System->Link('/news/'),
     160       'Link' =>  'http://'.$this->System->Config['Web']['Host'].$this->System->Link('/news/?a=item&amp;i='.$DbRow['Id']),
    139161       'Description' => $DbRow['Text'].' ('.$DbRow['Name'].')',
    140162       'Time' => $DbRow['UnixTime'],
Note: See TracChangeset for help on using the changeset viewer.