Ignore:
Timestamp:
Sep 12, 2013, 9:14:38 PM (11 years ago)
Author:
chronos
Message:
  • Modified: RSS channel management is now part of News module. In this module other modules can register their RSS channel which will be availble on all pages for subscription.
File:
1 edited

Legend:

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

    r578 r581  
    11<?php
     2
     3include_once(dirname(__FILE__).'/RSS.php');
    24
    35class ModuleNews extends AppModule
    46{
     7  var $RSSChannels;
     8 
    59  function __construct($System)
    610  {
     
    1721  {
    1822        $this->System->RegisterPage('news', 'PageNews');
    19         $this->System->RegisterRSS(array('Title' => 'Změny systému', 'Channel' => 'news'));
     23        $this->System->RegisterPage('rss', 'PageRSS');
     24        $this->RegisterRSS(array('Title' => 'Změny systému', 'Channel' => 'news',
     25          'Callback' => array('PageNews', 'ShowRSS'), 'Permission' => LICENCE_ANONYMOUS));
    2026  }
    2127 
     
    2430        $Output = '<strong>Změny systému:</strong><div class="NewsBox">';
    2531        $DbResult = $this->Database->query('SELECT `News`.`Time`, `User`.`Name`, `News`.`Text`,`News`.`Title`'.
    26                         ' FROM `News` JOIN `User` ON `User`.`ID` = `News`.`User` ORDER BY `Time` DESC LIMIT 10');
     32                ' FROM `News` JOIN `User` ON `User`.`ID` = `News`.`User` ORDER BY `Time` DESC LIMIT 10');
    2733        while($DbRow = $DbResult->fetch_assoc())
    2834                $Output .= '<div><strong>'.$DbRow['Title'].' ('.HumanDate($DbRow['Time']).')</strong> <br />'.$DbRow['Text'].' ('.$DbRow['Name'].')</div>';
    2935        $Output .= '<a href="'.$this->System->Link('/news/').'">Všechny zprávy</a>';
    30         $Output .= '</div>';
     36        $Output .= '</div>';   
    3137        return($Output);
     38  }
     39 
     40  function RegisterRSS($Channel, $Pos = NULL, $Callback = NULL)
     41  {
     42    $this->RSSChannels[$Channel['Channel']] = $Channel;
     43   
     44    if(is_null($Pos)) $this->RSSChannelsPos[] = $Channel['Channel'];
     45    else {
     46      array_splice($this->RSSChannelsPos, $Pos, 0, $Channel['Channel']);
     47    }
     48  }
     49 
     50  function ShowRSSHeader()
     51  {
     52    $Output = '';
     53    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                }               
     59    return($Output);
    3260  }
    3361}
     
    95123                return($Output);
    96124        }
     125       
     126        function ShowRSS()
     127        {
     128         $DbResult = $this->Database->query('SELECT UNIX_TIMESTAMP(`News`.`Time`) AS `UnixTime`, '.
     129           '`News`.`Title`, `News`.`Time`, `User`.`Name`, `News`.`Text` '.
     130           'FROM `News` JOIN `User` ON `User`.`ID` = `News`.`User` ORDER BY `Time` DESC LIMIT 10');
     131         while($DbRow = $DbResult->fetch_assoc())
     132         {
     133          $Items[] = array
     134          (
     135            'Title' => $DbRow['Title'],
     136            'Link' =>  'http://'.$this->System->Config['Web']['Host'].$this->System->Link('/'),
     137            'Description' => $DbRow['Text'].' ('.$DbRow['Name'].')',
     138            'Time' => $DbRow['UnixTime'],
     139          );
     140         }
     141         $Output = GenerateRSS(array
     142           (
     143             'Title' => 'WoW překlad - Změny systému',
     144             'Link' => 'http://'.$this->System->Config['Web']['Host'].$this->System->Link('/'),
     145             'Description' => 'Překlad textů WoW',
     146             'WebmasterEmail' => $this->System->Config['Web']['AdminEmail'],
     147             'Items' => $Items,
     148           ));
     149           return($Output);     
     150        }
    97151}
Note: See TracChangeset for help on using the changeset viewer.