source: trunk/aktuality/news.php@ 440

Last change on this file since 440 was 440, checked in by chronos, 13 years ago
  • Opraveno: Cesta k jednotce Global z generovacích skriptů.
  • Property svn:executable set to *
File size: 9.0 KB
Line 
1<?php
2
3function CategoryItemCompare($Item1, $Item2)
4{
5 if ($Item1['Index'] == $Item2['Index']) return(0);
6 return ($Item1['Index'] > $Item2['Index']) ? -1 : 1;
7}
8
9class 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(($I > 0) and ($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 if(strpos($Content, '<') !== false)
32 $URL = substr($Content, 0, strpos($Content, '<'));
33 else $URL = substr($Content, 0);
34 $Result .= '<a href="'.$URL.'">'.$URL.'</a>';
35 $Content = substr($Content, strlen($URL));
36 } else
37 {
38 $Result .= substr($Content, 0, $I + 1);
39 $Content = substr($Content, $I + 1);
40 }
41 }
42 $Result .= $Content;
43 return($Result);
44 }
45
46 function ShowNews($Category, $ItemCount, $DaysAgo)
47 {
48 global $Database, $NewsCategoryNames, $NewsCountPerCategory, $UploadedFilesFolder;
49
50 $ItemCount = abs($ItemCount);
51 $DaysAgo = abs($DaysAgo);
52 $DbResult = $Database->select('NewsCategory', '*', 'Id='.$Category);
53 $Row = $DbResult->fetch_array();
54 $Output = '<div class="NewsPanel"><div class="Title">'.$Row['Caption'];
55 $Output .= '<div class="Action"><a href="aktuality/index.php?category='.$Category.'">Zobrazit</a>';
56 if($this->System->Modules['User']->CheckPermission('News', 'Insert', 'Group', $Category))
57 $Output .= ' <a href="aktuality/index.php?action=add&amp;category='.$Category.'">Přidat</a>';
58 $Output .= '</div></div><div class="Content">';
59 $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);
60 //echo($Database->error.'<br />');
61 //echo($Database->LastQuery.'<br />');
62 //echo('<table cellpadding="0" cellspacing="0" width="100%"><tr><td>');
63 $Index = 0;
64 $FontSize = 12;
65 if($DbResult->num_rows > 0)
66 {
67 $Output .= '<table class="NewsTable">';
68 while($Row = $DbResult->fetch_array())
69 {
70 if($Row['Name'] == '') $Author = $Row['Author'];
71 else $Author = $Row['Name'];
72 $Output .= '<tr><td onclick="window.location=\'aktuality/index.php?action=view&amp;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>';
73 $Output .= '<div id="new'.$Category.$Index.'" class="NewsTableItem">'.$this->ModifyContent($Row['Content']);
74 if($Row['Link'] != '') $Output .= '<br/><a href="'.$Row['Link'].'">Odkaz</a>';
75
76 if($Row['Enclosure'] != '')
77 {
78 $Output .= '<br />Přílohy: ';
79 $Enclosures = explode(';', $Row['Enclosure']);
80 foreach($Enclosures as $Enclosure)
81 {
82 if(file_exists($UploadedFilesFolder.$Enclosure)) $Output .= ' <a href="'.$UploadedFilesFolder.$Enclosure.'">'.$Enclosure.'</a>';
83 }
84 }
85 $Output .= '</div></td></tr>';
86 $Index = $Index + 1;
87 $FontSize = $FontSize - 1;
88 }
89 $Output .= '</table>';
90 }
91 $Output .= '</div></div>';
92 return($Output);
93 }
94
95 function LoadSettingsFromCookies()
96 {
97 // Initialize default news setting
98 $this->NewsSetting = array();
99 $I = 1;
100 $DbResult = $this->Database->select('NewsCategory', '*', '1 ORDER BY Sequence');
101 while($NewsCategory = $DbResult->fetch_array())
102 {
103 $this->NewsSetting[] = array('CategoryId' => $NewsCategory['Id'], 'Index' => $I, 'Enabled' => 1, 'ItemCount' => $this->System->Config['Web']['News']['Count'], 'DaysAgo' => $this->System->Config['Web']['News']['DaysAgo'], 'Group' => $NewsCategory['Group']);
104 $I++;
105 }
106 // Merge defaults with user setting
107 if(array_key_exists('NewsSetting', $_COOKIE))
108 {
109 $NewsSettingCookie = unserialize($_COOKIE['NewsSetting']);
110 foreach($this->NewsSetting as $Index => $this->NewSetting)
111 {
112 if(array_key_exists($Index, $NewsSettingCookie))
113 $this->NewsSetting[$Index] = array_merge($this->NewSetting, $NewsSettingCookie[$Index]);
114 }
115 }
116 }
117
118 function Show()
119 {
120 $Output = '';
121
122 $UploadedFilesFolder = 'aktuality/uploads/';
123 $this->LoadSettingsFromCookies();
124
125 if(array_key_exists('Action', $_GET))
126 {
127 // Show news customize menu
128 if($_GET['Action'] == 'CustomizeNews')
129 {
130 $Output .= $this->ShowCustomizeMenu();
131 }
132 }
133
134 $Output .= '<div onmouseout="skryj(predchozi)">';
135
136 $ColumnCount = 2;
137 $Output .= '<table style="width: 100%"><tr>';
138 for($Column = 1; $Column <= $ColumnCount; $Column++)
139 {
140 $Output .= '<td style="vertical-align: top; width: '.round(100 / $ColumnCount).'%;">';
141 foreach($this->NewsSetting as $SettingItem)
142 if(($SettingItem['Enabled'] == 1) and ($SettingItem['Group'] == $Column))
143 $Output .= $this->ShowNews($SettingItem['CategoryId'], $SettingItem['ItemCount'], $SettingItem['DaysAgo']);
144 $Output .= '</td>';
145 }
146 $Output .= '</tr></table>';
147
148 $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>';
149 $Output .= '</div>';
150 return($Output);
151 }
152
153 function ShowCustomizeMenu()
154 {
155 $Output = '<form action="?Action=CustomizeNewsSave" method="post">';
156 $Output .= '<table width="100%" cellspacing="0" border="1"><tr><td><table cellspacing="0" width="100%">';
157 $Output .= '<tr><th>Kategorie</th><th>Pozice</th><th>Zobrazit</th><th>Max. počet</th><th>Posledních dnů</th><th>Sloupec</th></tr>';
158 $I = 0;
159 foreach($this->NewsSetting as $SettingItem)
160 {
161 $DbResult = $this->Database->select('NewsCategory', '*', 'Id='.$SettingItem['CategoryId']);
162 $NewsCategory = $DbResult->fetch_array();
163 $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.'"';
164 if($SettingItem['Enabled'] == 1) $Output .= ' checked="checked"';
165 $Output .= ' /></td>'.
166 '<td align="center"><input type="text" size="2" name="NewsCategoryCount'.$I.'" value="'.$SettingItem['ItemCount'].'" />'.
167 '<input type="hidden" name="NewsCategoryId'.$I.'" value="'.$SettingItem['CategoryId'].'" /></td>'.
168 '<td align="center"><input type="text" size="3" name="NewsCategoryDaysAgo'.$I.'" value="'.$SettingItem['DaysAgo'].'" /></td>'.
169 '<td><input type="text" size="3" name="NewsColumn'.$I.'" value="'.$SettingItem['Group'].'"/></td></tr>';
170 $I++;
171 }
172 $Output .= '</table><input type="hidden" name="NewsCategoryCount" value="'.count($this->NewsSetting).'" /><input type="submit" value="Uložit" /></form></td></tr></table><br>';
173 return($Output);
174 }
175
176 function CustomizeSave()
177 {
178 $Checkbox = array('' => 0, 'on' => 1);
179 // print_r($_POST);
180 $Setting = array();
181 for($I = 0; $I < $_POST['NewsCategoryCount']; $I++)
182 {
183 if(($_POST['NewsCategoryDaysAgo'.$I] * 1) < 0) $_POST['NewsCategoryIndex'.$I] = 0;
184 if(($_POST['NewsCategoryCount'.$I] * 1) < 0) $_POST['NewsCategoryCount'.$I] = 0;
185 if(($_POST['NewsColumn'.$I] * 1) < 1) $_POST['NewsColumn'.$I] = 1;
186 if(!array_key_exists('NewsCategoryEnabled'.$I, $_POST)) $_POST['NewsCategoryEnabled'.$I] = '';
187 $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),
188 'Group' => $_POST['NewsColumn'.$I]);
189 }
190 // Sort indexes
191 usort($Setting, 'CategoryItemCompare');
192 $Setting = array_reverse($Setting);
193 // Normalize indexes
194 foreach($Setting as $Index => $Item)
195 $Setting[$Index]['Index'] = $Index + 1;
196 // print_r($Setting);
197
198 // Store new cookie value
199 $_COOKIE['NewsSetting'] = serialize($Setting);
200 setcookie('NewsSetting', $_COOKIE['NewsSetting'], time() + 60 * 60 * 24 * 365);
201 }
202}
203
204?>
Note: See TracBrowser for help on using the repository browser.