source: trunk/aktuality/news.php@ 312

Last change on this file since 312 was 312, checked in by george, 14 years ago
  • Opraveno: Chyba indexování v obsahu aktualit.
  • Property svn:executable set to *
File size: 8.8 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 $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 = '<div class="NewsPanel"><div class="Title">'.$Row['Caption'];
52 $Output .= '<div class="Action"><a href="aktuality/index.php?category='.$Category.'">Zobrazit</a>';
53 if($this->System->Modules['User']->CheckPermission('News', 'Insert', 'Group', $Category))
54 $Output .= ' <a href="aktuality/index.php?action=add&amp;category='.$Category.'">Přidat</a>';
55 $Output .= '</div></div><div class="Content">';
56 $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);
57 //echo($Database->error.'<br />');
58 //echo($Database->LastQuery.'<br />');
59 //echo('<table cellpadding="0" cellspacing="0" width="100%"><tr><td>');
60 $Index = 0;
61 $FontSize = 12;
62 if($DbResult->num_rows > 0)
63 {
64 $Output .= '<table class="NewsTable">';
65 while($Row = $DbResult->fetch_array())
66 {
67 if($Row['Name'] == '') $Author = $Row['Author'];
68 else $Author = $Row['Name'];
69 $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>';
70 $Output .= '<div id="new'.$Category.$Index.'" class="NewsTableItem">'.$this->ModifyContent($Row['Content']);
71 if($Row['Link'] != '') $Output .= '<br/><a href="'.$Row['Link'].'">Odkaz</a>';
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 .= '</div></div>';
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', '*', '1 ORDER BY Sequence');
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'], 'Group' => $NewsCategory['Group']);
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 $ColumnCount = 2;
134 $Output .= '<table style="width: 100%"><tr>';
135 for($Column = 1; $Column <= $ColumnCount; $Column++)
136 {
137 $Output .= '<td style="vertical-align: top; width: '.round(100 / $ColumnCount).'%;">';
138 foreach($this->NewsSetting as $SettingItem)
139 if(($SettingItem['Enabled'] == 1) and ($SettingItem['Group'] == $Column))
140 $Output .= $this->ShowNews($SettingItem['CategoryId'], $SettingItem['ItemCount'], $SettingItem['DaysAgo']);
141 $Output .= '</td>';
142 }
143 $Output .= '</tr></table>';
144
145 $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>';
146 $Output .= '</div>';
147 return($Output);
148 }
149
150 function ShowCustomizeMenu()
151 {
152 $Output = '<form action="?Action=CustomizeNewsSave" method="post">';
153 $Output .= '<table width="100%" cellspacing="0" border="1"><tr><td><table cellspacing="0" width="100%">';
154 $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>';
155 $I = 0;
156 foreach($this->NewsSetting as $SettingItem)
157 {
158 $DbResult = $this->Database->select('NewsCategory', '*', 'Id='.$SettingItem['CategoryId']);
159 $NewsCategory = $DbResult->fetch_array();
160 $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.'"';
161 if($SettingItem['Enabled'] == 1) $Output .= ' checked="checked"';
162 $Output .= ' /></td>'.
163 '<td align="center"><input type="text" size="2" name="NewsCategoryCount'.$I.'" value="'.$SettingItem['ItemCount'].'" />'.
164 '<input type="hidden" name="NewsCategoryId'.$I.'" value="'.$SettingItem['CategoryId'].'" /></td>'.
165 '<td align="center"><input type="text" size="3" name="NewsCategoryDaysAgo'.$I.'" value="'.$SettingItem['DaysAgo'].'" /></td>'.
166 '<td><input type="text" size="3" name="NewsColumn'.$I.'" value="'.$SettingItem['Group'].'"/></td></tr>';
167 $I++;
168 }
169 $Output .= '</table><input type="hidden" name="NewsCategoryCount" value="'.count($this->NewsSetting).'" /><input type="submit" value="Uložit" /></form></td></tr></table><br>';
170 return($Output);
171 }
172
173 function CustomizeSave()
174 {
175 $Checkbox = array('' => 0, 'on' => 1);
176 // print_r($_POST);
177 $Setting = array();
178 for($I = 0; $I < $_POST['NewsCategoryCount']; $I++)
179 {
180 if(($_POST['NewsCategoryDaysAgo'.$I] * 1) < 0) $_POST['NewsCategoryIndex'.$I] = 0;
181 if(($_POST['NewsCategoryCount'.$I] * 1) < 0) $_POST['NewsCategoryCount'.$I] = 0;
182 if(($_POST['NewsColumn'.$I] * 1) < 1) $_POST['NewsColumn'.$I] = 1;
183 if(!array_key_exists('NewsCategoryEnabled'.$I, $_POST)) $_POST['NewsCategoryEnabled'.$I] = '';
184 $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),
185 'Group' => $_POST['NewsColumn'.$I]);
186 }
187 // Sort indexes
188 usort($Setting, 'CategoryItemCompare');
189 $Setting = array_reverse($Setting);
190 // Normalize indexes
191 foreach($Setting as $Index => $Item)
192 $Setting[$Index]['Index'] = $Index + 1;
193 // print_r($Setting);
194
195 // Store new cookie value
196 $_COOKIE['NewsSetting'] = serialize($Setting);
197 setcookie('NewsSetting', $_COOKIE['NewsSetting'], time() + 60 * 60 * 24 * 365);
198 }
199}
200
201?>
Note: See TracBrowser for help on using the repository browser.