Changeset 350
- Timestamp:
- Jan 18, 2012, 7:44:38 AM (13 years ago)
- Location:
- trunk/Modules/News
- Files:
-
- 2 deleted
- 2 edited
- 3 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/Modules/News/News.php
r348 r350 1 1 <?php 2 3 include_once('NewsPage.php'); 2 4 3 5 function CategoryItemCompare($Item1, $Item2) … … 7 9 } 8 10 9 class News extends OldModule 10 { 11 var $Dependencies = array('User', 'Log'); 12 var $NewsCountPerCategory = 3; 13 var $UploadedFilesFolder = 'aktuality/uploads/'; 14 11 class News extends Model 12 { 13 function __construct($Database, $System) 14 { 15 parent::__construct($Database, $System); 16 $this->Name = 'News'; 17 $this->AddPropertyString('Title'); 18 $this->AddPropertyText('Content'); 19 $this->AddPropertyDateTime('Date'); 20 $this->AddPropertyDateTime('TargetDate'); 21 $this->AddPropertyString('Author'); 22 $this->AddPropertyString('IP'); 23 $this->AddPropertyOneToMany('Category', 'NewsCategory'); 24 $this->AddPropertyString('Enclosure'); 25 $this->AddPropertyOneToMany('User', 'User'); 26 $this->AddPropertyString('Link'); 27 } 28 15 29 function ModifyContent($Content) 16 30 { … … 40 54 return($Result); 41 55 } 56 } 57 58 class NewsCategory extends Model 59 { 60 function __construct($Database, $System) 61 { 62 parent::__construct($Database, $System); 63 $this->Name = 'NewsCategory'; 64 $this->AddPropertyString('Caption'); 65 $this->AddPropertyInteger('Permission'); 66 $this->AddPropertyInteger('Sequence'); 67 $this->AddPropertyInteger('Group'); 68 $this->AddPropertyString('RSS'); 69 } 70 } 71 72 class ModuleNews extends Module 73 { 74 var $NewsCountPerCategory = 3; 75 var $UploadedFilesFolder = 'aktuality/uploads/'; 76 77 function __construct($Database, $System) 78 { 79 parent::__construct($Database, $System); 80 $this->Name = 'News'; 81 $this->Version = '1.0'; 82 $this->Creator = 'Chronos'; 83 $this->License = 'GNU/GPL'; 84 $this->Description = 'News and news groups management'; 85 $this->Dependencies = array('User', 'Log'); 86 $this->Models = array('News', 'NewsCategory'); 87 } 88 89 function Install() 90 { 91 parent::Install(); 92 } 93 94 function UnInstall() 95 { 96 parent::UnInstall(); 97 } 98 99 function Init() 100 { 101 $this->System->Pages['aktuality'] = 'NewsPage'; 102 } 42 103 43 104 function ShowNews($Category, $ItemCount, $DaysAgo) … … 50 111 $Row = $DbResult->fetch_array(); 51 112 $Output = '<div class="NewsPanel"><div class="Title">'.$Row['Caption']; 52 $Output .= '<div class="Action"><a href="aktuality/ index.php?category='.$Category.'">Zobrazit</a>';113 $Output .= '<div class="Action"><a href="aktuality/?category='.$Category.'">Zobrazit</a>'; 53 114 if($this->System->Models['User']->CheckPermission('News', 'Insert', 'Group', $Category)) 54 $Output .= ' <a href="aktuality/ index.php?action=add&category='.$Category.'">Přidat</a>';115 $Output .= ' <a href="aktuality/?action=add&category='.$Category.'">Přidat</a>'; 55 116 $Output .= '</div></div><div class="Content">'; 56 117 $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); … … 67 128 if($Row['Name'] == '') $Author = $Row['Author']; 68 129 else $Author = $Row['Name']; 69 $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>';130 $Output .= '<tr><td onclick="window.location=\'aktuality/?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>'; 70 131 $Output .= '<div id="new'.$Category.$Index.'" class="NewsTableItem">'.$this->ModifyContent($Row['Content']); 71 132 if($Row['Link'] != '') $Output .= '<br/><a href="'.$Row['Link'].'">Odkaz</a>'; … … 143 204 $Output .= '</tr></table>'; 144 205 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>';206 $Output .= '<a href="aktuality/subscription"><img class="RSSIcon" src="images/rss20.png" alt="Aktuality přes RSS" /></a> <a href="aktuality/subscription">Automatické sledování novinek</a>'; 146 207 $Output .= '</div>'; 147 208 return($Output); … … 197 258 setcookie('NewsSetting', $_COOKIE['NewsSetting'], time() + 60 * 60 * 24 * 365); 198 259 } 260 199 261 } 200 262 -
trunk/Modules/News/NewsPage.php
r348 r350 1 1 <?php 2 3 include_once('../global.php');4 2 5 3 class NewsPage extends Page … … 10 8 11 9 function Show() 10 { 11 if(count($this->System->PathItems) > 1) 12 { 13 if($this->System->PathItems[1] == 'subscription') return($this->ShowSubscription()); 14 else if($this->System->PathItems[1] == 'rss') return($this->ShowRSS()); 15 else return(PAGE_NOT_FOUND); 16 } else return($this->ShowMain()); 17 } 18 19 function ShowMain() 12 20 { 13 21 $Output = ''; … … 30 38 else 31 39 { 32 $News = new News($this->Database );40 $News = new News($this->Database, $this->System); 33 41 if(array_key_exists('id', $_GET)) $Id = $_GET['id'] * 1; 34 42 $DbResult = $this->Database->query('SELECT `News`.*, `User`.`Name` FROM `News` LEFT JOIN `User` ON `User`.`Id`=`News`.`User` WHERE `News`.`Id`='.$Id); … … 42 50 { 43 51 $Output .= '<div class="Action">'; 44 $Output .= ' <a href=" index.php?action=del&category='.$Category.'&id='.$Row['Id'].'">Smazat</a>';45 $Output .= ' <a href=" index.php?action=edit&category='.$Category.'&id='.$Row['Id'].'">Editovat</a>';52 $Output .= ' <a href="?action=del&category='.$Category.'&id='.$Row['Id'].'">Smazat</a>'; 53 $Output .= ' <a href="?action=edit&category='.$Category.'&id='.$Row['Id'].'">Editovat</a>'; 46 54 $Output .= '</div>'; 47 55 } … … 112 120 $this->Database->insert('News', array('Category' => $Category, 'Title' => $_POST['title'], 'Content' => $_POST['content'], 'Date' => 'NOW()', 'IP' => $RemoteAddr, 'Enclosure' => $Enclosures, 'Author' => $this->System->Models['User']->User['Name'], 'User' => $this->System->Models['User']->User['Id'], 'Link' => $_POST['link'])); 113 121 $Output .= 'Aktualita přidána!<br />Pokud budete chtít vaši aktualitu smazat, klikněte na odkaz Smazat v seznamu všech aktualit v kategorii.<br /><br />'; 114 $Output .= '<a href=" index.php?category='.$_POST['category'].'">Zpět na seznam aktualit</a>';122 $Output .= '<a href="?category='.$_POST['category'].'">Zpět na seznam aktualit</a>'; 115 123 $this->System->Modules['Log']->NewRecord('News', 'Aktualita přidána', $this->Database->insert_id); 116 124 } else $Output .= 'Do této kategorie nemůžete vkládat aktuality!'; … … 123 131 $Row['Content'] = str_replace('<br />', '', $Row['Content']); 124 132 $Output .= '<strong>Editace aktuality v kategorii '.$CategoryName.':</strong><br />'; 125 $Output .= '<form action=" index.php?action=update" method="post">'.133 $Output .= '<form action="?action=update" method="post">'. 126 134 '<input type="hidden" value="'.$_GET['id'].'" name="id">'. 127 135 'Nadpis:<br /><input type="text" size="54" name="title" value="'.$Row['Title'].'"><br />'. … … 164 172 } 165 173 $this->Database->query('DELETE FROM News WHERE Id='.$_GET['id']); 166 $Output .= 'Aktualita smazána!<br /><a href=" index.php?category='.$Category.'">Zpět na seznam aktualit</a>';174 $Output .= 'Aktualita smazána!<br /><a href="?category='.$Category.'">Zpět na seznam aktualit</a>'; 167 175 } else $Output .= 'Nemáte oprávnění.'; 168 176 break; … … 170 178 if($this->System->Models['User']->CheckPermission('News', 'Display', 'Group', $Category)) 171 179 { 172 $News = new News($this->Database );180 $News = new News($this->Database, $this->System); 173 181 $PerPage = 20; 174 182 $DbResult = $this->Database->select('News', 'COUNT(*)', ' Category='.$Category); … … 190 198 { 191 199 $Output .= '<div class="Action">'; 192 $Output .= ' <a href=" index.php?action=del&category='.$Category.'&id='.$Row['Id'].'">Smazat</a>';193 $Output .= ' <a href=" index.php?action=edit&category='.$Category.'&id='.$Row['Id'].'">Editovat</a>';200 $Output .= ' <a href="?action=del&category='.$Category.'&id='.$Row['Id'].'">Smazat</a>'; 201 $Output .= ' <a href="?action=edit&category='.$Category.'&id='.$Row['Id'].'">Editovat</a>'; 194 202 $Output .= '</div>'; 195 203 } … … 213 221 return($Output); 214 222 } 223 224 function ShowSubscription() 225 { 226 if(array_key_exists('build', $_GET)) 227 { 228 $Select = ''; 229 foreach($_POST as $Index => $Item) 230 { 231 if(substr($Index, 0, 8) == 'category') $Select .= '-'.substr($Index, 8); 232 } 233 $Select = $this->System->Config['Web']['RootFolder'].'/aktuality/rss/?select='.substr($Select, 1); 234 $Output = 'Výsledný RSS kanál: <a href="'.$Select.'">'.$Select.'</a>'; 235 } else 236 { 237 $Output = 'Vytvořte si vlastní RSS kanál, díky kterému budete moci automaticky sledovat novinky pomocí vaší RSS čtečky. Informace o technologii RSS a programech pro čtení kanálů najdete např. <a href="http://www.lupa.cz/clanky/prehled-rss-ctecek/">zde</a><br />'. 238 '<br />Kategorie:<br />'; 239 $Output .= '<form action="?build=1" method="post">'; 240 $DbResult = $this->Database->select('NewsCategory', '*', '1 ORDER BY Caption'); 241 while($Category = $DbResult->fetch_array()) 242 { 243 $Output .= '<input type="checkbox" name="category'.$Category['Id'].'" />'.$Category['Caption'].'<br />'; 244 } 245 $Output.= '<input type="submit" value="Sestavit " />'. 246 '</form>'; 247 } 248 return($Output); 249 } 250 251 function ShowRSS() 252 { 253 $this->SimplePage = true; 254 $this->FormatHTML = false; 255 Header('Content-Type: text/xml'); 256 257 include_once('rss_generator.php'); 258 259 $NewsCount = 15; 260 261 $Items = array(); 262 $Category = ''; 263 $CategoryOption = ''; 264 $CategoryOptionURL = ''; 265 $CategoryName = ''; 266 267 // Prepare WHERE condition 268 if(array_key_exists('select', $_GET)) 269 { 270 $Where = ''; 271 $Parts = explode('-', $_GET['select']); 272 foreach($Parts as $Part) 273 { 274 $Where .= 'OR (category='.($Part * 1).')'; 275 } 276 $Where = substr($Where, 2); 277 } else $Where = 1; 278 279 // Get category names 280 $Categories = array(); 281 $DbResult = $Database->select('NewsCategory', '*'); 282 while($Category = $DbResult->fetch_array()) 283 { 284 $Categories[$Category['Id']] = $Category['Caption']; 215 285 } 216 286 217 $System->AddModule(new NewsPage()); 218 $System->Modules['NewsPage']->GetOutput(); 287 // Update news from discussion forum 288 /* 289 $ForumCategory = 4; 290 $Database->select_db('forum'); 291 $DbResult = $Database->query('SELECT posts.post_time, posts_text.post_subject, posts_text.post_text, users.username, topics.topic_title FROM posts JOIN posts_text ON posts.post_id = posts_text.post_id JOIN users ON users.user_id = posts.poster_id JOIN topics ON topics.topic_id= posts.topic_id ORDER BY post_time DESC LIMIT '.$NewsCount); 292 $Index = 0; 293 //echo(DB_NumRows().','); 294 while($Row = $DbResult->fetch_array()) 295 { 296 $Row['post_text'] = StrTr($Row['post_text'], "\x8A\x8D\x8E\x9A\x9D\x9E", "\xA9\xAB\xAE\xB9\xBB\xBE"); 297 $Row['post_text'] = str_replace("\n","<br>", $Row['post_text']); 298 $Row['post_subject'] = StrTr($Row['post_subject'], "\x8A\x8D\x8E\x9A\x9D\x9E", "\xA9\xAB\xAE\xB9\xBB\xBE"); 299 $Row['topic_title'] = StrTr($Row['topic_title'], "\x8A\x8D\x8E\x9A\x9D\x9E", "\xA9\xAB\xAE\xB9\xBB\xBE"); 300 $Index = $Index + 1; 301 302 $Title = $Row['topic_title'].'-'.$Row['post_subject']; 303 $Content = $Row['post_text']; 304 $Date = date('Y-m-d H:i:s', $Row['post_time']); 305 $Author = $Row['username']; 306 $Database->select_db('is'); 307 //echo('category='.$ForumCategory.' AND title="'.addslashes($Title).'" AND content="'.addslashes($Content).'" AND author="'.addslashes($Author).'" AND date="'.$Date.'"'); 308 $DbResult2 = $Database->select('news', '*', 'category='.$ForumCategory.' AND title="'.addslashes($Title).'" AND content="'.addslashes($Content).'" AND author="'.addslashes($Author).'" AND date="'.$Date.'"'); 309 if($DbResult2->num_rows == 0) //echo('.'); else echo('x'); 310 $Database->insert('news', array('category' => $ForumCategory, 'title' => $Title, 'content' => $Content, 'author' => $Author, 'date' => $Date)); 311 //echo($Date); 312 $Database->select_db('forum'); 313 } 314 $Database->select_db('is'); 315 */ 316 317 // Get news from database by selected categories 318 $UploadedFilesFolder = 'uploads/'; 319 $DbResult = $Database->query('SELECT *, UNIX_TIMESTAMP(Date) FROM News LEFT JOIN `User` ON `User`.`Id`=`News`.`User` WHERE '.$Where.' ORDER BY News.Date DESC LIMIT 0,'.$NewsCount); 320 while($Row = $DbResult->fetch_assoc()) 321 { 322 $EnclosuresText = ''; 323 if($Row['Enclosure'] != '') 324 { 325 $EnclosuresText .= '<br />Přílohy: '; 326 $Enclosures = explode(';', $Row['Enclosure']); 327 foreach($Enclosures as $Enclosure) 328 { 329 if(file_exists($UploadedFilesFolder.$Enclosure)) $EnclosuresText .= ' <a href="http://centrala.zdechov.net/aktuality/'.$UploadedFilesFolder.$Enclosure.'">'.$Enclosure.'</a>'; 330 } 331 } 332 if($Row['Name'] == '') $Author = $Row['Author']; 333 else $Author = $Row['Name']; 334 $Items[] = array( 335 'Title' => $Categories[$Row['Category']].' - '.$Row['Title'], 336 'Link' => 'http://centrala.zdechov.net/aktuality/index.php?category='.$Row['Category'], 337 'Description' => $Row['Content'].' ('.$Author.')'.$EnclosuresText, 338 'Time' => $Row['UNIX_TIMESTAMP(Date)'], 339 ); 340 } 341 342 return(GenerateRSS(array( 343 'Title' => $Config['Web']['Title'].' - Aktuality', 344 'Link' => 'http://'.$Config['Web']['Host'].'/', 345 'Description' => 'Aktuality komunitní počítačové sítě ZděchovNET', 346 'WebmasterEmail' => $Config['Web']['AdminEmail'], 347 'Items' => $Items))); 348 349 } 350 351 } 219 352 220 353 ?> -
trunk/Modules/News/rss.php
r196 r350 1 1 <?php 2 2 3 Header('Content-Type: text/xml');4 5 include_once('../global.php');6 include_once('rss_generator.php');7 8 $NewsCount = 15;9 10 $Items = array();11 $Category = '';12 $CategoryOption = '';13 $CategoryOptionURL = '';14 $CategoryName = '';15 16 // Prepare WHERE condition17 if(array_key_exists('select', $_GET))18 {19 $Where = '';20 $Parts = explode('-', $_GET['select']);21 foreach($Parts as $Part)22 {23 $Where .= 'OR (category='.($Part * 1).')';24 }25 $Where = substr($Where, 2);26 } else $Where = 1;27 28 // Get category names29 $Categories = array();30 $DbResult = $Database->select('NewsCategory', '*');31 while($Category = $DbResult->fetch_array())32 {33 $Categories[$Category['Id']] = $Category['Caption'];34 }35 36 // Update news from discussion forum37 /*38 $ForumCategory = 4;39 $Database->select_db('forum');40 $DbResult = $Database->query('SELECT posts.post_time, posts_text.post_subject, posts_text.post_text, users.username, topics.topic_title FROM posts JOIN posts_text ON posts.post_id = posts_text.post_id JOIN users ON users.user_id = posts.poster_id JOIN topics ON topics.topic_id= posts.topic_id ORDER BY post_time DESC LIMIT '.$NewsCount);41 $Index = 0;42 //echo(DB_NumRows().',');43 while($Row = $DbResult->fetch_array())44 {45 $Row['post_text'] = StrTr($Row['post_text'], "\x8A\x8D\x8E\x9A\x9D\x9E", "\xA9\xAB\xAE\xB9\xBB\xBE");46 $Row['post_text'] = str_replace("\n","<br>", $Row['post_text']);47 $Row['post_subject'] = StrTr($Row['post_subject'], "\x8A\x8D\x8E\x9A\x9D\x9E", "\xA9\xAB\xAE\xB9\xBB\xBE");48 $Row['topic_title'] = StrTr($Row['topic_title'], "\x8A\x8D\x8E\x9A\x9D\x9E", "\xA9\xAB\xAE\xB9\xBB\xBE");49 $Index = $Index + 1;50 51 $Title = $Row['topic_title'].'-'.$Row['post_subject'];52 $Content = $Row['post_text'];53 $Date = date('Y-m-d H:i:s', $Row['post_time']);54 $Author = $Row['username'];55 $Database->select_db('is');56 //echo('category='.$ForumCategory.' AND title="'.addslashes($Title).'" AND content="'.addslashes($Content).'" AND author="'.addslashes($Author).'" AND date="'.$Date.'"');57 $DbResult2 = $Database->select('news', '*', 'category='.$ForumCategory.' AND title="'.addslashes($Title).'" AND content="'.addslashes($Content).'" AND author="'.addslashes($Author).'" AND date="'.$Date.'"');58 if($DbResult2->num_rows == 0) //echo('.'); else echo('x');59 $Database->insert('news', array('category' => $ForumCategory, 'title' => $Title, 'content' => $Content, 'author' => $Author, 'date' => $Date));60 //echo($Date);61 $Database->select_db('forum');62 }63 $Database->select_db('is');64 */65 66 // Get news from database by selected categories67 $UploadedFilesFolder = 'uploads/';68 $DbResult = $Database->query('SELECT *, UNIX_TIMESTAMP(Date) FROM News LEFT JOIN `User` ON `User`.`Id`=`News`.`User` WHERE '.$Where.' ORDER BY News.Date DESC LIMIT 0,'.$NewsCount);69 while($Row = $DbResult->fetch_assoc())70 {71 $EnclosuresText = '';72 if($Row['Enclosure'] != '')73 {74 $EnclosuresText .= '<br />Přílohy: ';75 $Enclosures = explode(';', $Row['Enclosure']);76 foreach($Enclosures as $Enclosure)77 {78 if(file_exists($UploadedFilesFolder.$Enclosure)) $EnclosuresText .= ' <a href="http://centrala.zdechov.net/aktuality/'.$UploadedFilesFolder.$Enclosure.'">'.$Enclosure.'</a>';79 }80 }81 if($Row['Name'] == '') $Author = $Row['Author'];82 else $Author = $Row['Name'];83 $Items[] = array(84 'Title' => $Categories[$Row['Category']].' - '.$Row['Title'],85 'Link' => 'http://centrala.zdechov.net/aktuality/index.php?category='.$Row['Category'],86 'Description' => $Row['Content'].' ('.$Author.')'.$EnclosuresText,87 'Time' => $Row['UNIX_TIMESTAMP(Date)'],88 );89 }90 91 echo(GenerateRSS(array(92 'Title' => $Config['Web']['Title'].' - Aktuality',93 'Link' => 'http://'.$Config['Web']['Host'].'/',94 'Description' => 'Aktuality komunitní počítačové sítě ZděchovNET',95 'WebmasterEmail' => $Config['Web']['AdminEmail'],96 'Items' => $Items)));97 3 98 4 ?> -
trunk/Modules/News/subscription.php
r196 r350 8 8 var $ShortTitle = 'RSS kanál'; 9 9 10 function Show()11 {12 if(array_key_exists('build', $_GET))13 {14 $Select = '';15 foreach($_POST as $Index => $Item)16 {17 if(substr($Index, 0, 8) == 'category') $Select .= '-'.substr($Index, 8);18 }19 $Select = $this->System->Config['Web']['RootFolder'].'/aktuality/rss.php?select='.substr($Select, 1);20 $Output = 'Výsledný RSS kanál: <a href="'.$Select.'">'.$Select.'</a>';21 } else22 {23 $Output = 'Vytvořte si vlastní RSS kanál, díky kterému budete moci automaticky sledovat novinky pomocí vaší RSS čtečky. Informace o technologii RSS a programech pro čtení kanálů najdete např. <a href="http://www.lupa.cz/clanky/prehled-rss-ctecek/">zde</a><br />'.24 '<br />Kategorie:<br />';25 $Output .= '<form action="subscription.php?build=1" method="post">';26 $DbResult = $this->Database->select('NewsCategory', '*', '1 ORDER BY Caption');27 while($Category = $DbResult->fetch_array())28 {29 $Output .= '<input type="checkbox" name="category'.$Category['Id'].'" />'.$Category['Caption'].'<br />';30 }31 $Output.= '<input type="submit" value="Sestavit " />'.32 '</form>';33 }34 return($Output);35 }36 10 } 37 11
Note:
See TracChangeset
for help on using the changeset viewer.