1 | <?php
|
---|
2 |
|
---|
3 | class ModuleRSS extends Module
|
---|
4 | {
|
---|
5 | var $RSSChannels;
|
---|
6 |
|
---|
7 | function __construct($System)
|
---|
8 | {
|
---|
9 | parent::__construct($System);
|
---|
10 | $this->Name = 'RSS';
|
---|
11 | $this->Version = '1.0';
|
---|
12 | $this->Creator = 'Chronos';
|
---|
13 | $this->License = 'GNU/GPL';
|
---|
14 | $this->Description = 'Web site RSS channel management';
|
---|
15 | $this->Dependencies = array();
|
---|
16 | $this->RSSChannels = array();
|
---|
17 | }
|
---|
18 |
|
---|
19 | function Start(): void
|
---|
20 | {
|
---|
21 | $this->System->RegisterPage(array('rss'), 'PageRSS');
|
---|
22 | Core::Cast($this->System)->RegisterPageHeader('RSS', array($this, 'ShowRSSHeader'));
|
---|
23 | }
|
---|
24 |
|
---|
25 | function RegisterRSS(array $Channel, ?int $Pos = NULL, $Callback = NULL): void
|
---|
26 | {
|
---|
27 | $this->RSSChannels[$Channel['Channel']] = $Channel;
|
---|
28 |
|
---|
29 | if (is_null($Pos)) $this->RSSChannelsPos[] = $Channel['Channel'];
|
---|
30 | else {
|
---|
31 | array_splice($this->RSSChannelsPos, $Pos, 0, $Channel['Channel']);
|
---|
32 | }
|
---|
33 | }
|
---|
34 |
|
---|
35 | function UnregisterRSS(string $ChannelName): void
|
---|
36 | {
|
---|
37 | unset($this->RSSChannels[$ChannelName]);
|
---|
38 | // TODO: Remove channel from pos list
|
---|
39 | }
|
---|
40 |
|
---|
41 | function ShowRSSHeader(): string
|
---|
42 | {
|
---|
43 | $Output = '';
|
---|
44 | foreach ($this->RSSChannels as $Channel)
|
---|
45 | {
|
---|
46 | //if ($this->System->User->Licence($Channel['Permission']))
|
---|
47 | $Output .= ' <link rel="alternate" title="'.$Channel['Title'].'" href="'.
|
---|
48 | $this->System->Link('/rss/?channel='.$Channel['Channel']).'" type="application/rss+xml" />';
|
---|
49 | }
|
---|
50 | return $Output;
|
---|
51 | }
|
---|
52 | }
|
---|
53 |
|
---|
54 | class PageRSS extends Page
|
---|
55 | {
|
---|
56 | function Show(): string
|
---|
57 | {
|
---|
58 | $this->RawPage = true;
|
---|
59 |
|
---|
60 | if (array_key_exists('channel', $_GET)) $ChannelName = $_GET['channel'];
|
---|
61 | else $ChannelName = '';
|
---|
62 | if (array_key_exists('token', $_GET)) $Token = $_GET['token'];
|
---|
63 | else $Token = '';
|
---|
64 | if (array_key_exists($ChannelName, $this->System->ModuleManager->Modules['RSS']->RSSChannels))
|
---|
65 | {
|
---|
66 | $Channel = $this->System->ModuleManager->Modules['RSS']->RSSChannels[$ChannelName];
|
---|
67 | if ($this->System->User->CheckPermission($Channel['Permission']['Module'], $Channel['Permission']['Operation']) or
|
---|
68 | $this->System->User->CheckToken($Channel['Permission']['Module'], $Channel['Permission']['Operation'], $Token))
|
---|
69 | {
|
---|
70 | if (is_string($Channel['Callback'][0]))
|
---|
71 | {
|
---|
72 | $Class = new $Channel['Callback'][0]($this->System);
|
---|
73 | $Method = $Channel['Callback'][1];
|
---|
74 | $Output = $Class->$Method();
|
---|
75 | } else $Output = call_user_func($Channel['Callback']);
|
---|
76 | } else $Output = 'Nemáte oprávnění';
|
---|
77 | } else $Output = 'Kanál nenalezen';
|
---|
78 | return $Output;
|
---|
79 | }
|
---|
80 | }
|
---|