Changeset 816 for trunk/Modules/News/News.php
- Timestamp:
- Feb 22, 2015, 11:20:50 PM (10 years ago)
- File:
-
- 1 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 }
Note:
See TracChangeset
for help on using the changeset viewer.