1 | <?php
|
---|
2 |
|
---|
3 | function CategoryItemCompare($Item1, $Item2)
|
---|
4 | {
|
---|
5 | if ($Item1['Index'] == $Item2['Index']) return(0);
|
---|
6 | return ($Item1['Index'] > $Item2['Index']) ? -1 : 1;
|
---|
7 | }
|
---|
8 |
|
---|
9 | class News extends Module
|
---|
10 | {
|
---|
11 | var $Dependencies = array('User', 'Log');
|
---|
12 | var $NewsCountPerCategory = 3;
|
---|
13 | var $UploadedFilesFolder = 'aktuality/uploads/';
|
---|
14 |
|
---|
15 | function ModifyContent($Content)
|
---|
16 | {
|
---|
17 | $Result = '';
|
---|
18 |
|
---|
19 | // Make HTML link from URL
|
---|
20 | $I = 0;
|
---|
21 | while(strpos($Content, 'http://') !== false)
|
---|
22 | {
|
---|
23 | $I = strpos($Content, 'http://');
|
---|
24 | if($Content{$I - 1} != '"')
|
---|
25 | {
|
---|
26 | $Result .= substr($Content, 0, $I);
|
---|
27 | $Content = substr($Content, $I);
|
---|
28 | if(strpos($Content, ' ') !== false)
|
---|
29 | $URL = substr($Content, 0, strpos($Content, ' '));
|
---|
30 | else $URL = substr($Content, 0);
|
---|
31 | $Result .= '<a href="'.$URL.'">'.$URL.'</a>';
|
---|
32 | $Content = substr($Content, strlen($URL));
|
---|
33 | } else
|
---|
34 | {
|
---|
35 | $Result .= substr($Content, 0, $I + 1);
|
---|
36 | $Content = substr($Content, $I + 1);
|
---|
37 | }
|
---|
38 | }
|
---|
39 | $Result .= $Content;
|
---|
40 | return($Result);
|
---|
41 | }
|
---|
42 |
|
---|
43 | function ShowNews($Category, $ItemCount, $DaysAgo)
|
---|
44 | {
|
---|
45 | global $Database, $NewsCategoryNames, $NewsCountPerCategory, $UploadedFilesFolder;
|
---|
46 |
|
---|
47 | $ItemCount = abs($ItemCount);
|
---|
48 | $DaysAgo = abs($DaysAgo);
|
---|
49 | $DbResult = $Database->select('NewsCategory', '*', 'Id='.$Category);
|
---|
50 | $Row = $DbResult->fetch_array();
|
---|
51 | $Output = '<table class="NewsBaseTable"><tr>';
|
---|
52 | $Output .= '<td>'.$Row['Caption'].'</td><td align="right">';
|
---|
53 | $Output .= '<a href="aktuality/index.php?category='.$Category.'">Zobrazit všechny aktuality</a> ';
|
---|
54 | if($this->System->Modules['User']->CheckPermission('News', 'Insert', 'Group', $Category))
|
---|
55 | $Output .= '<a href="aktuality/index.php?action=add&category='.$Category.'">Přidat aktualitu</a> ';
|
---|
56 | $Output .= '</td></tr><tr><td colspan="2">';
|
---|
57 | $DbResult = $Database->query('SELECT `News`.*, `User`.`Name` FROM `News` LEFT JOIN `User` ON `User`.`Id`=`News`.`User` WHERE (`News`.`Category`='.$Category.') AND (DATE_SUB(NOW(), INTERVAL '.$DaysAgo.' DAY) < `News`.`Date`) ORDER BY `News`.`Date` DESC LIMIT 0,'.$ItemCount);
|
---|
58 | //echo($Database->error.'<br />');
|
---|
59 | //echo($Database->LastQuery.'<br />');
|
---|
60 | //echo('<table cellpadding="0" cellspacing="0" width="100%"><tr><td>');
|
---|
61 | $Index = 0;
|
---|
62 | $FontSize = 12;
|
---|
63 | if($DbResult->num_rows > 0)
|
---|
64 | {
|
---|
65 | $Output .= '<table class="NewsTable">';
|
---|
66 | while($Row = $DbResult->fetch_array())
|
---|
67 | {
|
---|
68 | if($Row['Name'] == '') $Author = $Row['Author'];
|
---|
69 | else $Author = $Row['Name'];
|
---|
70 | $Output .= '<tr><td onclick="window.location=\'aktuality/index.php?action=view&id='.$Row['Id'].'\'" onmouseover="zobraz('."'new".$Category.$Index."'".')" style="cursor: pointer; margin: 0px;"><table class="NewsItemFrame"><tr><td style="font-size: '.$FontSize.'pt"><strong>'.$Row['Title'].'</strong></td><td align="right" style="font-size: '.$FontSize.'pt">'.$Author.' ('.HumanDate($Row['Date']).')</td></tr></table>';
|
---|
71 | $Output .= '<div id="new'.$Category.$Index.'" class="NewsTableItem">'.$this->ModifyContent($Row['Content']);
|
---|
72 |
|
---|
73 | if($Row['Enclosure'] != '')
|
---|
74 | {
|
---|
75 | $Output .= '<br />Přílohy: ';
|
---|
76 | $Enclosures = explode(';', $Row['Enclosure']);
|
---|
77 | foreach($Enclosures as $Enclosure)
|
---|
78 | {
|
---|
79 | if(file_exists($UploadedFilesFolder.$Enclosure)) $Output .= ' <a href="'.$UploadedFilesFolder.$Enclosure.'">'.$Enclosure.'</a>';
|
---|
80 | }
|
---|
81 | }
|
---|
82 | $Output .= '</div></td></tr>';
|
---|
83 | $Index = $Index + 1;
|
---|
84 | $FontSize = $FontSize - 1;
|
---|
85 | }
|
---|
86 | $Output .= '</table>';
|
---|
87 | }
|
---|
88 | $Output .= '</td></tr></table>';
|
---|
89 | return($Output);
|
---|
90 | }
|
---|
91 |
|
---|
92 | function LoadSettingsFromCookies()
|
---|
93 | {
|
---|
94 | // Initialize default news setting
|
---|
95 | $this->NewsSetting = array();
|
---|
96 | $I = 1;
|
---|
97 | $DbResult = $this->Database->select('NewsCategory', '*');
|
---|
98 | while($NewsCategory = $DbResult->fetch_array())
|
---|
99 | {
|
---|
100 | $this->NewsSetting[] = array('CategoryId' => $NewsCategory['Id'], 'Index' => $I, 'Enabled' => 1, 'ItemCount' => $this->System->Config['Web']['News']['Count'], 'DaysAgo' => $this->System->Config['Web']['News']['DaysAgo']);
|
---|
101 | $I++;
|
---|
102 | }
|
---|
103 | // Merge defaults with user setting
|
---|
104 | if(array_key_exists('NewsSetting', $_COOKIE))
|
---|
105 | {
|
---|
106 | $NewsSettingCookie = unserialize($_COOKIE['NewsSetting']);
|
---|
107 | foreach($this->NewsSetting as $Index => $this->NewSetting)
|
---|
108 | {
|
---|
109 | if(array_key_exists($Index, $NewsSettingCookie))
|
---|
110 | $this->NewsSetting[$Index] = array_merge($this->NewSetting, $NewsSettingCookie[$Index]);
|
---|
111 | }
|
---|
112 | }
|
---|
113 | }
|
---|
114 |
|
---|
115 | function Show()
|
---|
116 | {
|
---|
117 | $Output = '';
|
---|
118 |
|
---|
119 | $UploadedFilesFolder = 'aktuality/uploads/';
|
---|
120 | $this->LoadSettingsFromCookies();
|
---|
121 |
|
---|
122 | if(array_key_exists('Action', $_GET))
|
---|
123 | {
|
---|
124 | // Show news customize menu
|
---|
125 | if($_GET['Action'] == 'CustomizeNews')
|
---|
126 | {
|
---|
127 | $Output .= $this->ShowCustomizeMenu();
|
---|
128 | }
|
---|
129 | }
|
---|
130 |
|
---|
131 | $Output .= '<div onmouseout="skryj(predchozi)">';
|
---|
132 |
|
---|
133 | foreach($this->NewsSetting as $SettingItem)
|
---|
134 | if($SettingItem['Enabled'] == 1) $Output .= $this->ShowNews($SettingItem['CategoryId'], $SettingItem['ItemCount'], $SettingItem['DaysAgo']);
|
---|
135 |
|
---|
136 | $Output .= '<a href="aktuality/subscription.php"><img class="RSSIcon" src="images/rss20.png" alt="Aktuality přes RSS" /></a> <a href="aktuality/subscription.php">Automatické sledování novinek</a>';
|
---|
137 | $Output .= '</div>';
|
---|
138 | return($Output);
|
---|
139 | }
|
---|
140 |
|
---|
141 | function ShowCustomizeMenu()
|
---|
142 | {
|
---|
143 | $Output = '<form action="?Action=CustomizeNewsSave" method="post">';
|
---|
144 | $Output .= '<table width="100%" cellspacing="0" border="1"><tr><td><table cellspacing="0" width="100%">';
|
---|
145 | $Output .= '<tr><th>Kategorie</th><th>Pozice</th><th>Zobrazit</th><th>Max. počet</th><th>Posledních dnů</th></tr>';
|
---|
146 | $I = 0;
|
---|
147 | foreach($this->NewsSetting as $SettingItem)
|
---|
148 | {
|
---|
149 | $DbResult = $this->Database->select('NewsCategory', '*', 'Id='.$SettingItem['CategoryId']);
|
---|
150 | $NewsCategory = $DbResult->fetch_array();
|
---|
151 | $Output .= '<tr><td>'.$NewsCategory['Caption'].'</td><td align="center"><input type="text" size="2" name="NewsCategoryIndex'.$I.'" value="'.$SettingItem['Index'].'" /></td><td align="center"><input type="checkbox" name="NewsCategoryEnabled'.$I.'"';
|
---|
152 | if($SettingItem['Enabled'] == 1) $Output .= ' checked="checked"';
|
---|
153 | $Output .= ' /></td>'.
|
---|
154 | '<td align="center"><input type="text" size="2" name="NewsCategoryCount'.$I.'" value="'.$SettingItem['ItemCount'].'" />'.
|
---|
155 | '<input type="hidden" name="NewsCategoryId'.$I.'" value="'.$SettingItem['CategoryId'].'" /></td>'.
|
---|
156 | '<td align="center"><input type="text" size="3" name="NewsCategoryDaysAgo'.$I.'" value="'.$SettingItem['DaysAgo'].'" /></td></tr>';
|
---|
157 | $I++;
|
---|
158 | }
|
---|
159 | $Output .= '</table><input type="hidden" name="NewsCategoryCount" value="'.count($this->NewsSetting).'" /><input type="submit" value="Uložit" /></form></td></tr></table>';
|
---|
160 | return($Output);
|
---|
161 | }
|
---|
162 |
|
---|
163 | function CustomizeSave()
|
---|
164 | {
|
---|
165 | $Checkbox = array('' => 0, 'on' => 1);
|
---|
166 | // print_r($_POST);
|
---|
167 | $Setting = array();
|
---|
168 | for($I = 0; $I < $_POST['NewsCategoryCount']; $I++)
|
---|
169 | {
|
---|
170 | if(($_POST['NewsCategoryDaysAgo'.$I] * 1) < 0) $_POST['NewsCategoryIndex'.$I] = 0;
|
---|
171 | if(($_POST['NewsCategoryCount'.$I] * 1) < 0) $_POST['NewsCategoryCount'.$I] = 0;
|
---|
172 | if(!array_key_exists('NewsCategoryEnabled'.$I, $_POST)) $_POST['NewsCategoryEnabled'.$I] = '';
|
---|
173 | $Setting[] = array('CategoryId' => $_POST['NewsCategoryId'.$I], 'Enabled' => $Checkbox[$_POST['NewsCategoryEnabled'.$I]], 'ItemCount' => ($_POST['NewsCategoryCount'.$I]*1), 'DaysAgo' => ($_POST['NewsCategoryDaysAgo'.$I]*1), 'Index' => ($_POST['NewsCategoryIndex'.$I]*1));
|
---|
174 | }
|
---|
175 | // Sort indexes
|
---|
176 | usort($Setting, 'CategoryItemCompare');
|
---|
177 | $Setting = array_reverse($Setting);
|
---|
178 | // Normalize indexes
|
---|
179 | foreach($Setting as $Index => $Item)
|
---|
180 | $Setting[$Index]['Index'] = $Index + 1;
|
---|
181 | // print_r($Setting);
|
---|
182 |
|
---|
183 | // Store new cookie value
|
---|
184 | $_COOKIE['NewsSetting'] = serialize($Setting);
|
---|
185 | setcookie('NewsSetting', $_COOKIE['NewsSetting'], time() + 60 * 60 * 24 * 365);
|
---|
186 | }
|
---|
187 | }
|
---|
188 |
|
---|
189 | ?>
|
---|