source: trunk/Modules/News/News.php@ 608

Last change on this file since 608 was 608, checked in by chronos, 11 years ago
  • Added: Implemented mechanism for update interface translation list from source code. Resulted list is saved to lanugage file and database.
File size: 5.5 KB
Line 
1<?php
2
3include_once(dirname(__FILE__).'/RSS.php');
4
5class 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' => 'Změny systému', 'Channel' => 'news',
25 'Callback' => array('PageNews', 'ShowRSS'), 'Permission' => LICENCE_ANONYMOUS));
26 }
27
28 function ShowBox()
29 {
30 $Output = '<strong>Změny systému:</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
63class PageNews extends Page
64{
65 function Show()
66 {
67 if(array_key_exists('a', $_POST)) $Action = $_POST['a'];
68 else if(array_key_exists('a', $_GET)) $Action = $_GET['a'];
69 else $Action = '';
70 if($Action == 'add2') $Output = $this->SaveNew();
71 if($Action == 'add') $Output = $this->ShowAddForm();
72 else $Output = $this->ShowList();
73 return($Output);
74 }
75
76 function ShowList()
77 {
78 $DbResult = $this->System->Database->query('SELECT COUNT(*) FROM `News`');
79 $DbRow = $DbResult->fetch_row();
80 $PageList = GetPageList($DbRow[0]);
81
82 $Output = '<h3>Novinky</h3>'.$PageList['Output'];
83 if($this->System->User->Licence(LICENCE_ADMIN))
84 $Output .= ' <a href="?a=add">'.T('Add').'</a>';
85 $Output .= '<div class="shoutbox">';
86 $DbResult = $this->System->Database->query('SELECT `News`.`Time`, `News`.`Text`, `News`.`Title`, '.
87 '`User`.`Name` AS `User` FROM `News` JOIN `User` ON `User`.`Id`=`News`.`User` ORDER BY `News`.`Time` DESC '.$PageList['SQLLimit']);
88 while($Line = $DbResult->fetch_assoc())
89 $Output .= '<div><strong>'.$Line['Title'].' ('.HumanDate($Line['Time']).')</strong><br/> '.$Line['Text'].' ('.$Line['User'].')</div>';
90 $Output .= '</div>'.$PageList['Output'];
91 return($Output);
92 }
93
94 function ShowAddForm()
95 {
96 if($this->System->User->Licence(LICENCE_ADMIN))
97 {
98 $Output = '<form action="?" method="POST">'.
99 'Uživatel: '.$this->System->User->Name.'('.$this->System->User->Id.')<br/> '.
100 'Nadpis: <input type="text" name="title" size="40"/><br/>'.
101 'Obsah: <textarea rows="8" cols="40" onkeydown="ResizeTextArea(this)" class="textedit" id="Text" name="text"></textarea><br/>'.
102 '<input type="hidden" name="a" value="add2"/>'.
103 '<input type="submit" value="Uložit"/><br/>'.
104 '</form>';
105 } else $Output = ShowMessage(T('Access denied'), MESSAGE_CRITICAL);
106 return($Output);
107 }
108
109 function SaveNew()
110 {
111 if($this->System->User->Licence(LICENCE_ADMIN))
112 {
113 if(array_key_exists('text', $_POST) and array_key_exists('title', $_POST))
114 {
115 $querty = 'INSERT INTO `News` (`Title`, `Time` ,`User` ,`Text`) VALUES ( "'.$_POST['title'].'", NOW( ) , '.
116 $this->System->User->Id.', "'.$_POST['text'].'")';
117 $this->System->Database->query($querty);
118 $Output = ShowMessage('Aktualita uložena.');
119 $this->System->ModuleManager->Modules['Log']->WriteLog('Vložena nová aktualita', LOG_TYPE_ADMINISTRATION);
120 $Output .= $this->ShowList();
121 } else $Output = ShowMessage('Nezadány údaje', MESSAGE_CRITICAL);
122 } else $Output = ShowMessage(T('Access denied'), MESSAGE_CRITICAL);
123 return($Output);
124 }
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 }
151}
Note: See TracBrowser for help on using the repository browser.