Changeset 581 for trunk/Modules/News
- Timestamp:
- Sep 12, 2013, 9:14:38 PM (11 years ago)
- Location:
- trunk/Modules/News
- Files:
-
- 1 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/Modules/News/News.php
r578 r581 1 1 <?php 2 3 include_once(dirname(__FILE__).'/RSS.php'); 2 4 3 5 class ModuleNews extends AppModule 4 6 { 7 var $RSSChannels; 8 5 9 function __construct($System) 6 10 { … … 17 21 { 18 22 $this->System->RegisterPage('news', 'PageNews'); 19 $this->System->RegisterRSS(array('Title' => 'Změny systému', 'Channel' => 'news')); 23 $this->System->RegisterPage('rss', 'PageRSS'); 24 $this->RegisterRSS(array('Title' => 'Změny systému', 'Channel' => 'news', 25 'Callback' => array('PageNews', 'ShowRSS'), 'Permission' => LICENCE_ANONYMOUS)); 20 26 } 21 27 … … 24 30 $Output = '<strong>Změny systému:</strong><div class="NewsBox">'; 25 31 $DbResult = $this->Database->query('SELECT `News`.`Time`, `User`.`Name`, `News`.`Text`,`News`.`Title`'. 26 32 ' FROM `News` JOIN `User` ON `User`.`ID` = `News`.`User` ORDER BY `Time` DESC LIMIT 10'); 27 33 while($DbRow = $DbResult->fetch_assoc()) 28 34 $Output .= '<div><strong>'.$DbRow['Title'].' ('.HumanDate($DbRow['Time']).')</strong> <br />'.$DbRow['Text'].' ('.$DbRow['Name'].')</div>'; 29 35 $Output .= '<a href="'.$this->System->Link('/news/').'">Všechny zprávy</a>'; 30 $Output .= '</div>'; 36 $Output .= '</div>'; 31 37 return($Output); 38 } 39 40 function RegisterRSS($Channel, $Pos = NULL, $Callback = NULL) 41 { 42 $this->RSSChannels[$Channel['Channel']] = $Channel; 43 44 if(is_null($Pos)) $this->RSSChannelsPos[] = $Channel['Channel']; 45 else { 46 array_splice($this->RSSChannelsPos, $Pos, 0, $Channel['Channel']); 47 } 48 } 49 50 function ShowRSSHeader() 51 { 52 $Output = ''; 53 foreach($this->RSSChannels as $Channel) 54 { 55 if($this->System->User->Licence($Channel['Permission'])) 56 $Output .= ' <link rel="alternate" title="'.$Channel['Title'].'" href="'. 57 $this->System->Link('/rss/?channel='.$Channel['Channel']).'" type="application/rss+xml" />'; 58 } 59 return($Output); 32 60 } 33 61 } … … 95 123 return($Output); 96 124 } 125 126 function ShowRSS() 127 { 128 $DbResult = $this->Database->query('SELECT UNIX_TIMESTAMP(`News`.`Time`) AS `UnixTime`, '. 129 '`News`.`Title`, `News`.`Time`, `User`.`Name`, `News`.`Text` '. 130 'FROM `News` JOIN `User` ON `User`.`ID` = `News`.`User` ORDER BY `Time` DESC LIMIT 10'); 131 while($DbRow = $DbResult->fetch_assoc()) 132 { 133 $Items[] = array 134 ( 135 'Title' => $DbRow['Title'], 136 'Link' => 'http://'.$this->System->Config['Web']['Host'].$this->System->Link('/'), 137 'Description' => $DbRow['Text'].' ('.$DbRow['Name'].')', 138 'Time' => $DbRow['UnixTime'], 139 ); 140 } 141 $Output = GenerateRSS(array 142 ( 143 'Title' => 'WoW překlad - Změny systému', 144 'Link' => 'http://'.$this->System->Config['Web']['Host'].$this->System->Link('/'), 145 'Description' => 'Překlad textů WoW', 146 'WebmasterEmail' => $this->System->Config['Web']['AdminEmail'], 147 'Items' => $Items, 148 )); 149 return($Output); 150 } 97 151 } -
trunk/Modules/News/RSS.php
r578 r581 1 1 <?php 2 2 3 $InitSystem = true; 4 include_once('includes/global.php'); 5 6 $Items = array(); 7 if($_GET['channel'] == 'news') 8 { 9 $DbResult = $System->Database->query('SELECT UNIX_TIMESTAMP(`News`.`Time`) AS `UnixTime`, '. 10 '`News`.`Title`, `News`.`Time`, `User`.`Name`, `News`.`Text` '. 11 'FROM `News` JOIN `User` ON `User`.`ID` = `News`.`User` ORDER BY `Time` DESC LIMIT 10'); 12 while($DbRow = $DbResult->fetch_assoc()) 13 { 14 $Items[] = array 15 ( 16 'Title' => $DbRow['Title'], 17 'Link' => 'http://'.$Config['Web']['Host'].$System->Link('/'), 18 'Description' => $DbRow['Text'].' ('.$DbRow['Name'].')', 19 'Time' => $DbRow['UnixTime'], 20 ); 21 } 22 echo(GenerateRSS(array 23 ( 24 'Title' => 'WoW překlad - Změny systému', 25 'Link' => 'http://'.$Config['Web']['Host'].$System->Link('/'), 26 'Description' => 'Překlad textů WoW', 27 'WebmasterEmail' => $Config['Web']['AdminEmail'], 28 'Items' => $Items, 29 ))); 30 } else 31 if($_GET['channel'] == 'translation') 32 { 33 $DbResult = $System->Database->query('SELECT UNIX_TIMESTAMP(`Date`) AS `Date`, `User`.`Name` AS `UserName`, `Text` FROM `Log` JOIN `User` ON `User`.`ID` = `Log`.`User` WHERE `Type` = 1 ORDER BY `Date` DESC LIMIT 100'); 34 while($DbRow = $DbResult->fetch_assoc()) 35 { 36 $Items[] = array 37 ( 38 'Title' => strip_tags($DbRow['Text'].' ('.$DbRow['UserName'].')'), 39 'Link' => 'http://'.$Config['Web']['Host'].$System->Link('/'), 40 'Description' => $DbRow['Text'], 41 'Time' => $DbRow['Date'], 42 ); 43 } 44 echo(GenerateRSS(array 45 ( 46 'Title' => 'WoW překlad - Poslední překlady', 47 'Link' => 'http://'.$Config['Web']['Host'].$System->Link('/'), 48 'Description' => 'Překlad textů WoW', 49 'WebmasterEmail' => $Config['Web']['AdminEmail'], 50 'Items' => $Items, 51 ))); 52 } else 53 if($_GET['channel'] == 'shoutbox') 54 { 55 $TitleLength = 50; 56 mb_internal_encoding('utf-8'); 57 $DbResult = $System->Database->query('SELECT UNIX_TIMESTAMP(`Date`) AS `UnixDate`, `User`, `UserName`, `Text` FROM `ShoutBox` ORDER BY `ID` DESC LIMIT 20'); 58 while($DbRow = $DbResult->fetch_assoc()) 59 { 60 $Title = mb_substr($DbRow['Text'], 0, $TitleLength); 61 if(mb_strlen($Title) == $TitleLength) $Title .= '...'; 62 $Items[] = array 63 ( 64 'Title' => $DbRow['UserName'].': '.$Title, 65 'Link' => 'http://'.$Config['Web']['Host'].$System->Link('/'), 66 'Description' => $DbRow['Text'], 67 'Time' => $DbRow['UnixDate'], 68 ); 69 } 70 echo(GenerateRSS(array 71 ( 72 'Title' => 'WoW překlad - Shoutbox', 73 'Link' => 'http://'.$Config['Web']['Host'].$System->Link('/'), 74 'Description' => 'Překlad textů WoW', 75 'WebmasterEmail' => $Config['Web']['AdminEmail'], 76 'Items' => $Items, 77 ))); 78 } else echo('Nezadán žádný kanál'); 3 function GenerateRSS($Data) 4 { 5 global $Config; 6 7 $Result = '<?xml version="1.0" encoding="'.$Config['Web']['Charset'].'" ?>'."\n". //<? 8 '<rss version="2.0">'."\n". 9 " <channel>\n". 10 " <title>".$Data['Title']."</title>\n". 11 " <link>".$Data['Link']."</link>\n". 12 " <description>".$Data['Description']."</description>\n". 13 " <language>cs</language>\n". 14 " <webMaster>".$Data['WebmasterEmail']."</webMaster>\n". 15 " <pubDate>".date('r')."</pubDate>\n". 16 " <ttl>20</ttl>\n"; 17 foreach($Data['Items'] as $Item) 18 { 19 $Result .= " <item>\n". 20 ' <title>'.htmlspecialchars($Item['Title'])."</title>\n". 21 ' <description>'.htmlspecialchars($Item['Description'])."</description>\n". 22 ' <pubDate>'.date('r',$Item['Time'])."</pubDate>\n". 23 ' <link>'.$Item['Link']."</link>\n". 24 " </item>\n"; 25 } 26 $Result .= " </channel>\n". 27 "</rss>"; 28 return($Result); 29 } 30 31 class PageRSS extends Page 32 { 33 function Show() 34 { 35 $this->RawPage = true; 36 37 if(array_key_exists($_GET['channel'], $this->System->ModuleManager->Modules['News']->RSSChannels)) 38 { 39 $Channel = $this->System->ModuleManager->Modules['News']->RSSChannels[$_GET['channel']]; 40 if($this->System->User->Licence($Channel['Permission'])) 41 { 42 if(is_string($Channel['Callback'][0])) 43 { 44 $Class = new $Channel['Callback'][0]($this->System); 45 $Output = $Class->$Channel['Callback'][1](); 46 } else $Output = call_user_func($Channel['Callback']); 47 } else $Output = 'Nemáte oprávnění'; 48 } else $Output = 'Nezadán žádný kanál'; 49 return($Output); 50 } 51 }
Note:
See TracChangeset
for help on using the changeset viewer.