1 | <?php
|
---|
2 |
|
---|
3 | include_once(dirname(__FILE__).'/RSS.php');
|
---|
4 |
|
---|
5 | class ModuleNews extends AppModule
|
---|
6 | {
|
---|
7 | var $RSSChannels;
|
---|
8 |
|
---|
9 | function __construct($System)
|
---|
10 | {
|
---|
11 | parent::__construct($System);
|
---|
12 | $this->Name = 'News';
|
---|
13 | $this->Version = '1.0';
|
---|
14 | $this->Creator = 'Chronos';
|
---|
15 | $this->License = 'GNU/GPL';
|
---|
16 | $this->Description = 'Web site annoucements management';
|
---|
17 | $this->Dependencies = array();
|
---|
18 | }
|
---|
19 |
|
---|
20 | function Start()
|
---|
21 | {
|
---|
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));
|
---|
26 | }
|
---|
27 |
|
---|
28 | function ShowBox()
|
---|
29 | {
|
---|
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);
|
---|
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);
|
---|
60 | }
|
---|
61 | }
|
---|
62 |
|
---|
63 | class PageNews extends Page
|
---|
64 | {
|
---|
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 | }
|
---|
76 |
|
---|
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 | }
|
---|
94 |
|
---|
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();
|
---|
130 | $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 | }
|
---|
153 | }
|
---|