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