Changeset 816 for trunk/Modules/News
- Timestamp:
- Feb 22, 2015, 11:20:50 PM (10 years ago)
- Location:
- trunk/Modules/News
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Modules/News/News.php
r815 r816 20 20 function Start() 21 21 { 22 23 24 25 22 $this->System->RegisterPage('news', 'PageNews'); 23 $this->System->RegisterPage('rss', 'PageRSS'); 24 $this->RegisterRSS(array('Title' => T('News'), 'Channel' => 'news', 25 'Callback' => array('PageNews', 'ShowRSS'), 'Permission' => LICENCE_ANONYMOUS)); 26 26 } 27 27 28 28 function ShowBox() 29 29 { 30 31 32 33 34 35 36 $Output .= '</div>';37 30 $Output = '<strong>'.T('System changes').':</strong><div class="NewsBox">'; 31 $DbResult = $this->Database->query('SELECT `News`.`Time`, `User`.`Name`, `News`.`Text`,`News`.`Title`'. 32 ' FROM `News` JOIN `User` ON `User`.`ID` = `News`.`User` ORDER BY `Time` DESC LIMIT 10'); 33 while($DbRow = $DbResult->fetch_assoc()) 34 $Output .= '<div><strong>'.$DbRow['Title'].' ('.HumanDate($DbRow['Time']).')</strong> <br />'.$DbRow['Text'].' ('.$DbRow['Name'].')</div>'; 35 $Output .= '<a href="'.$this->System->Link('/news/').'">'.T('All news').'</a>'; 36 $Output .= '</div>'; 37 return($Output); 38 38 } 39 39 … … 41 41 { 42 42 $this->RSSChannels[$Channel['Channel']] = $Channel; 43 43 44 44 if(is_null($Pos)) $this->RSSChannelsPos[] = $Channel['Channel']; 45 45 else { … … 52 52 $Output = ''; 53 53 foreach($this->RSSChannels as $Channel) 54 55 56 57 58 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 59 return($Output); 60 60 } … … 63 63 class PageNews extends Page 64 64 { 65 66 67 68 69 70 71 72 73 74 75 65 function Show() 66 { 67 $this->Title = T('News'); 68 if(array_key_exists('a', $_POST)) $Action = $_POST['a']; 69 else if(array_key_exists('a', $_GET)) $Action = $_GET['a']; 70 else $Action = ''; 71 if($Action == 'add2') $Output = $this->SaveNew(); 72 if($Action == 'add') $Output = $this->ShowAddForm(); 73 else $Output = $this->ShowList(); 74 return($Output); 75 } 76 76 77 function ShowList() 78 { 79 $DbResult = $this->System->Database->query('SELECT COUNT(*) FROM `News`'); 80 $DbRow = $DbResult->fetch_row(); 81 $PageList = GetPageList($DbRow[0]); 82 83 $Output = '<h3>'.T('News').'</h3>'.$PageList['Output']; 84 if($this->System->User->Licence(LICENCE_ADMIN)) 85 $Output .= ' <a href="?a=add">'.T('Add').'</a>'; 86 $Output .= '<div class="shoutbox">'; 87 $DbResult = $this->System->Database->query('SELECT `News`.`Time`, `News`.`Text`, `News`.`Title`, '. 88 '`User`.`Name` AS `User` FROM `News` JOIN `User` ON `User`.`Id`=`News`.`User` ORDER BY `News`.`Time` DESC '.$PageList['SQLLimit']); 89 while($Line = $DbResult->fetch_assoc()) 90 $Output .= '<div><strong>'.$Line['Title'].' ('.HumanDate($Line['Time']).')</strong><br/> '.$Line['Text'].' ('.$Line['User'].')</div>'; 91 $Output .= '</div>'.$PageList['Output']; 92 return($Output); 93 } 77 function ShowList() 78 { 79 $DbResult = $this->System->Database->query('SELECT COUNT(*) FROM `News`'); 80 $DbRow = $DbResult->fetch_row(); 81 $PageList = GetPageList($DbRow[0]); 94 82 95 function ShowAddForm() 96 { 97 if($this->System->User->Licence(LICENCE_ADMIN)) 98 { 99 $Output = '<form action="?" method="POST">'. 100 T('User').': '.$this->System->User->Name.'('.$this->System->User->Id.')<br/> '. 101 T('Title').': <input type="text" name="title" size="40"/><br/>'. 102 T('Content').': <textarea rows="8" cols="40" onkeydown="ResizeTextArea(this)" class="textedit" id="Text" name="text"></textarea><br/>'. 103 '<input type="hidden" name="a" value="add2"/>'. 104 '<input type="submit" value="'.T('Save').'"/><br/>'. 105 '</form>'; 106 } else $Output = ShowMessage(T('Access denied'), MESSAGE_CRITICAL); 107 return($Output); 108 } 109 110 function SaveNew() 111 { 112 if($this->System->User->Licence(LICENCE_ADMIN)) 113 { 114 if(array_key_exists('text', $_POST) and array_key_exists('title', $_POST)) 115 { 116 $querty = 'INSERT INTO `News` (`Title`, `Time` ,`User` ,`Text`) VALUES ( "'.$_POST['title'].'", NOW( ) , '. 117 $this->System->User->Id.', "'.$_POST['text'].'")'; 118 $this->System->Database->query($querty); 119 $Output = ShowMessage(T('News added')); 120 $this->System->ModuleManager->Modules['Log']->WriteLog('Vložena nová aktualita', LOG_TYPE_ADMINISTRATION); 121 $Output .= $this->ShowList(); 122 } else $Output = ShowMessage(T('Data not specified'), MESSAGE_CRITICAL); 123 } else $Output = ShowMessage(T('Access denied'), MESSAGE_CRITICAL); 124 return($Output); 125 } 83 $Output = '<h3>'.T('News').'</h3>'.$PageList['Output']; 84 if($this->System->User->Licence(LICENCE_ADMIN)) 85 $Output .= ' <a href="?a=add">'.T('Add').'</a>'; 86 $Output .= '<div class="shoutbox">'; 87 $DbResult = $this->System->Database->query('SELECT `News`.`Time`, `News`.`Text`, `News`.`Title`, '. 88 '`User`.`Name` AS `User` FROM `News` JOIN `User` ON `User`.`Id`=`News`.`User` ORDER BY `News`.`Time` DESC '.$PageList['SQLLimit']); 89 while($Line = $DbResult->fetch_assoc()) 90 $Output .= '<div><strong>'.$Line['Title'].' ('.HumanDate($Line['Time']).')</strong><br/> '.$Line['Text'].' ('.$Line['User'].')</div>'; 91 $Output .= '</div>'.$PageList['Output']; 92 return($Output); 93 } 126 94 127 function ShowRSS() 128 { 129 $Items = array(); 95 function ShowAddForm() 96 { 97 if($this->System->User->Licence(LICENCE_ADMIN)) 98 { 99 $Output = '<form action="?" method="POST">'. 100 T('User').': '.$this->System->User->Name.'('.$this->System->User->Id.')<br/> '. 101 T('Title').': <input type="text" name="title" size="40"/><br/>'. 102 T('Content').': <textarea rows="8" cols="40" onkeydown="ResizeTextArea(this)" class="textedit" id="Text" name="text"></textarea><br/>'. 103 '<input type="hidden" name="a" value="add2"/>'. 104 '<input type="submit" value="'.T('Save').'"/><br/>'. 105 '</form>'; 106 } else $Output = ShowMessage(T('Access denied'), MESSAGE_CRITICAL); 107 return($Output); 108 } 109 110 function SaveNew() 111 { 112 if($this->System->User->Licence(LICENCE_ADMIN)) 113 { 114 if(array_key_exists('text', $_POST) and array_key_exists('title', $_POST)) 115 { 116 $querty = 'INSERT INTO `News` (`Title`, `Time` ,`User` ,`Text`) VALUES ( "'.$_POST['title'].'", NOW( ) , '. 117 $this->System->User->Id.', "'.$_POST['text'].'")'; 118 $this->System->Database->query($querty); 119 $Output = ShowMessage(T('News added')); 120 $this->System->ModuleManager->Modules['Log']->WriteLog('Vložena nová aktualita', LOG_TYPE_ADMINISTRATION); 121 $Output .= $this->ShowList(); 122 } else $Output = ShowMessage(T('Data not specified'), MESSAGE_CRITICAL); 123 } else $Output = ShowMessage(T('Access denied'), MESSAGE_CRITICAL); 124 return($Output); 125 } 126 127 function ShowRSS() 128 { 129 $Items = array(); 130 130 $DbResult = $this->Database->query('SELECT UNIX_TIMESTAMP(`News`.`Time`) AS `UnixTime`, '. 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 131 '`News`.`Title`, `News`.`Time`, `User`.`Name`, `News`.`Text` '. 132 'FROM `News` JOIN `User` ON `User`.`ID` = `News`.`User` ORDER BY `Time` DESC LIMIT 10'); 133 while($DbRow = $DbResult->fetch_assoc()) 134 { 135 $Items[] = array 136 ( 137 'Title' => $DbRow['Title'], 138 'Link' => 'http://'.$this->System->Config['Web']['Host'].$this->System->Link('/news/'), 139 'Description' => $DbRow['Text'].' ('.$DbRow['Name'].')', 140 'Time' => $DbRow['UnixTime'], 141 ); 142 } 143 $Output = GenerateRSS(array 144 ( 145 'Title' => $this->System->Config['Web']['Title'].' - '.T('System changes'), 146 'Link' => 'http://'.$this->System->Config['Web']['Host'].$this->System->Link('/news/'), 147 'Description' => $this->System->Config['Web']['Description'], 148 'WebmasterEmail' => $this->System->Config['Web']['AdminEmail'], 149 'Items' => $Items, 150 )); 151 return($Output); 152 } 153 153 } -
trunk/Modules/News/RSS.php
r609 r816 3 3 function GenerateRSS($Data) 4 4 { 5 5 global $Config; 6 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 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 29 } 30 30 31 31 class PageRSS extends Page 32 32 { 33 34 { 35 36 37 38 39 40 41 42 43 $Channel = $this->System->ModuleManager->Modules['News']->RSSChannels[$ChannelName]; 44 if($this->System->User->Licence($Channel['Permission']) or 45 46 47 48 49 50 51 52 53 33 function Show() 34 { 35 $this->RawPage = true; 36 37 if(array_key_exists('channel', $_GET)) $ChannelName = $_GET['channel']; 38 else $ChannelName = ''; 39 if(array_key_exists('token', $_GET)) $Token = $_GET['token']; 40 else $Token = ''; 41 if(array_key_exists($ChannelName, $this->System->ModuleManager->Modules['News']->RSSChannels)) 42 { 43 $Channel = $this->System->ModuleManager->Modules['News']->RSSChannels[$ChannelName]; 44 if($this->System->User->Licence($Channel['Permission']) or 45 $this->System->User->CheckToken($Channel['Permission'], $Token)) 46 { 47 if(is_string($Channel['Callback'][0])) 48 { 49 $Class = new $Channel['Callback'][0]($this->System); 50 $Output = $Class->$Channel['Callback'][1](); 51 } else $Output = call_user_func($Channel['Callback']); 52 } else $Output = T('Access denied'); 53 } else $Output = 'Nezadán žádný kanál'; 54 54 return($Output); 55 55 } 56 56 }
Note:
See TracChangeset
for help on using the changeset viewer.