source: www/aktuality/news.php@ 151

Last change on this file since 151 was 151, checked in by george, 16 years ago
  • Přidáno: Import aktualit z webu zdechov.cz
  • Upraveno: Přepracovány aktuality na nový systém.
  • Property svn:executable set to *
File size: 7.5 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 ShowNews($Category, $ItemCount, $DaysAgo)
16 {
17 global $Database, $NewsCategoryNames, $NewsCountPerCategory, $UploadedFilesFolder;
18
19 $ItemCount = abs($ItemCount);
20 $DaysAgo = abs($DaysAgo);
21 $DbResult = $Database->select('news_category', '*', 'id='.$Category);
22 $Row = $DbResult->fetch_array();
23 $Output = '<table cellspacing="0" cellpadding="0" border="0" width="100%" style="font-size: small; padding-bottom: 5px;"><tr>';
24 $Output .= '<td>'.$Row['caption'].'</td><td align="right">';
25 $Output .= '<a href="aktuality/index.php?category='.$Category.'">Zobrazit všechny aktuality</a>&nbsp;';
26 if($this->System->Modules['User']->CheckPermission('News', 'Insert', 'Group', $Category))
27 $Output .= '<a href="aktuality/index.php?action=add&amp;category='.$Category.'">Přidat aktualitu</a>&nbsp;';
28 $Output .= '</td></tr><tr><td colspan="2">';
29 $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);
30 //echo($Database->error.'<br />');
31 //echo($Database->LastQuery.'<br />');
32 //echo('<table cellpadding="0" cellspacing="0" width="100%"><tr><td>');
33 $Index = 0;
34 $FontSize = 12;
35 if($DbResult->num_rows > 0)
36 {
37 $Output .= '<table cellspacing="0" width="100%" class="NewsTable">';
38 while($Row = $DbResult->fetch_array())
39 {
40 $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 cellspacing="0" cellpadding="0" style="padding: 0px; margin: 0px; font-size: small; color: red;" width="100%"><tr><td style="font-size: '.$FontSize.'pt"><strong>'.$Row['title'].'</strong></td><td align="right" style="font-size: '.$FontSize.'pt">'.$Row['Name'].$Row['author'].' ('.HumanDate($Row['date']).')</td></tr></table>';
41 $Output .= '<div id="new'.$Category.$Index.'" class="NewsTableItem">'.$Row['content'];
42
43 if($Row['enclosure'] != '')
44 {
45 $Output .= '<br />Přílohy: ';
46 $Enclosures = explode(';', $Row['enclosure']);
47 foreach($Enclosures as $Enclosure)
48 {
49 if(file_exists($UploadedFilesFolder.$Enclosure)) $Output .= ' <a href="'.$UploadedFilesFolder.$Enclosure.'">'.$Enclosure.'</a>';
50 }
51 }
52
53 $Output .= '</div></td></tr>';
54 $Index = $Index + 1;
55 $FontSize = $FontSize - 1;
56 }
57 $Output .= '</table>';
58 }
59 $Output .= '</td></tr></table>'."\n\n";
60 return($Output);
61 }
62
63 function LoadSettingsFromCookies()
64 {
65 // Initialize default news setting
66 $this->NewsSetting = array();
67 $I = 1;
68 $DbResult = $this->Database->select('news_category', '*');
69 while($NewsCategory = $DbResult->fetch_array())
70 {
71 $this->NewsSetting[] = array('CategoryId' => $NewsCategory['id'], 'Index' => $I, 'Enabled' => 1, 'ItemCount' => $this->System->Config['Web']['News']['Count'], 'DaysAgo' => $this->System->Config['Web']['News']['DaysAgo']);
72 $I++;
73 }
74 // Merge defaults with user setting
75 if(array_key_exists('NewsSetting', $_COOKIE))
76 {
77 $NewsSettingCookie = unserialize($_COOKIE['NewsSetting']);
78 foreach($this->NewsSetting as $Index => $this->NewSetting)
79 {
80 $this->NewsSetting[$Index] = array_merge($this->NewSetting, $NewsSettingCookie[$Index]);
81 }
82 }
83 }
84
85 function Show()
86 {
87 $Output = '<div class="PanelTitle"><span class="MenuItem">Aktuálně:</span><div class="MenuItem2"><a href="?Action=CustomizeNews">Upravit</a></div></div>';
88
89 $UploadedFilesFolder = 'aktuality/uploads/';
90 $this->LoadSettingsFromCookies();
91
92 if(array_key_exists('Action', $_GET))
93 {
94 // Show news customize menu
95 if($_GET['Action'] == 'CustomizeNews')
96 {
97 $Output .= $this->ShowCustomizeMenu();
98 }
99 }
100
101 $Output .= '<div onmouseout="skryj(predchozi)">';
102
103 foreach($this->NewsSetting as $SettingItem)
104 if($SettingItem['Enabled'] == 1) $Output .= $this->ShowNews($SettingItem['CategoryId'], $SettingItem['ItemCount'], $SettingItem['DaysAgo']);
105
106 $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>';
107 $Output .= '</div>';
108 return($Output);
109 }
110
111 function ShowCustomizeMenu()
112 {
113 $Output = '<form action="?Action=CustomizeNewsSave" method="post">';
114 $Output .= '<table width="100%" cellspacing="0" border="1"><tr><td><table cellspacing="0" width="100%">';
115 $Output .= '<tr><th>Kategorie</th><th>Pozice</th><th>Zobrazit</th><th>Max. počet</th><th>Posledních dnů</th></tr>';
116 $I = 0;
117 foreach($this->NewsSetting as $SettingItem)
118 {
119 $DbResult = $this->Database->select('news_category', '*', 'id='.$SettingItem['CategoryId']);
120 $NewsCategory = $DbResult->fetch_array();
121 $Output .= '<tr><td>'.$NewsCategory['caption'].'</td><td align="center"><input type="text" size="1" name="NewsCategoryIndex'.$I.'" value="'.$SettingItem['Index'].'" /></td><td align="center"><input type="checkbox" name="NewsCategoryEnabled'.$I.'"';
122 if($SettingItem['Enabled'] == 1) $Output .= ' checked="checked"';
123 $Output .= ' /></td>'.
124 '<td align="center"><input type="text" size="1" name="NewsCategoryCount'.$I.'" value="'.$SettingItem['ItemCount'].'" />'.
125 '<input type="hidden" name="NewsCategoryId'.$I.'" value="'.$SettingItem['CategoryId'].'" /></td><td align="center"><input type="text" size="1" name="NewsCategoryDaysAgo'.$I.'" value="'.$SettingItem['DaysAgo'].'" /></td></tr>';
126 $I++;
127 }
128 $Output .= '</table><input type="hidden" name="NewsCategoryCount" value="'.count($this->NewsSetting).'" /><input type="submit" value="Uložit" /></form></td></tr></table>';
129 return($Output);
130 }
131
132 function CustomizeSave()
133 {
134 $Checkbox = array('' => 0, 'on' => 1);
135 // print_r($_POST);
136 $Setting = array();
137 for($I = 0; $I < $_POST['NewsCategoryCount']; $I++)
138 {
139 if(($_POST['NewsCategoryDaysAgo'.$I] * 1) < 0) $_POST['NewsCategoryIndex'.$I] = 0;
140 if(($_POST['NewsCategoryCount'.$I] * 1) < 0) $_POST['NewsCategoryCount'.$I] = 0;
141 if(!array_key_exists('NewsCategoryEnabled'.$I, $_POST)) $_POST['NewsCategoryEnabled'.$I] = '';
142 $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));
143 }
144 // Sort indexes
145 usort($Setting, 'CategoryItemCompare');
146 $Setting = array_reverse($Setting);
147 // Normalize indexes
148 foreach($Setting as $Index => $Item)
149 $Setting[$Index]['Index'] = $Index + 1;
150 // print_r($Setting);
151
152 // Store new cookie value
153 $_COOKIE['NewsSetting'] = serialize($Setting);
154 setcookie('NewsSetting', $_COOKIE['NewsSetting']);
155 }
156
157}
158
159
160?>
Note: See TracBrowser for help on using the repository browser.