Changeset 816 for trunk/Modules/Referrer/Referrer.php
- Timestamp:
- Feb 22, 2015, 11:20:50 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Modules/Referrer/Referrer.php
r811 r816 3 3 class ModuleReferrer extends AppModule 4 4 { 5 5 var $Excludes; 6 6 7 7 function __construct($System) … … 20 20 function Start() 21 21 { 22 23 24 25 26 27 28 29 22 $this->Log(); 23 $this->System->RegisterPage('referrer', 'PageReferrer'); 24 $this->System->RegisterMenuItem(array( 25 'Title' => T('Promotion'), 26 'Hint' => 'Informace k propagaci tohoto projektu', 27 'Link' => $this->System->Link('/referrer/'), 28 'Permission' => LICENCE_ANONYMOUS, 29 'Icon' => '', 30 30 )); 31 31 } … … 40 40 if(!in_array($HostName, $this->Excludes)) 41 41 { 42 42 $IP = GetRemoteAddress(); 43 43 44 44 // Check if client IP is not blaclisted as spam source. If yes then add new referrer as invisible … … 65 65 { 66 66 $this->System->Database->query('INSERT INTO `Referrer` (`Web`, `DateFirst`, `DateLast`, `LastURL`, `Hits`, `LastIP`, `Visible`, `Description`) '. 67 67 'VALUES ("'.$HostName.'", NOW(), NOW( ), "'.addslashes($Referrer).'", 1, "'.$IP.'", '.$Visible.', "'.$Description.'")'); 68 68 } 69 69 } … … 93 93 $MonthAge = 3; 94 94 $YesNo = array('Ne', 'Ano'); 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 95 $Output .= '<br/><strong>'.T('Servers referring to us').':</strong> <br /> 96 <div style="font-size: 10px;">Seznam je automaticky aktualizován a zobrazeny jsou servery, ze kterých přišli uživatelé během posledních třech měsíců řazený sestupně dle nejnovějších.</div><br />'; 97 98 if(!$this->System->User->Licence(LICENCE_ADMIN)) $Where = ' WHERE (`Visible`=1) AND (`Parent` IS NULL)'; 99 else $Where = ''; 100 $Query = 'SELECT *, (SELECT Web FROM `Referrer` AS T4 WHERE T4.Id = T3.Parent) AS ParentName '. 101 'FROM (SELECT *, '. 102 '(`Hits` + COALESCE((SELECT SUM(`Hits`) FROM '. 103 '`Referrer` AS `T1` WHERE `T1`.`Parent` = `T2`.`Id`), 0)) AS `TotalHits`, '. 104 'GREATEST(`DateLast`, COALESCE((SELECT MAX(`DateLast`) FROM '. 105 '`Referrer` AS `T1` WHERE `T1`.`Parent` = `T2`.`Id`), 0)) AS `MaxDateLast` FROM '. 106 '`Referrer` AS `T2` '.$Where.') AS `T3` '. 107 'WHERE (`T3`.`MaxDateLast` > (NOW() - INTERVAL '.$MonthAge.' MONTH))'; 108 109 110 $DbResult = $this->Database->query('SELECT COUNT(*) FROM ('.$Query.') AS T'); 111 $DbRow = $DbResult->fetch_row(); 112 $PageList = GetPageList($DbRow[0]); 113 114 $Output .= $PageList['Output']. 115 '<table class="BaseTable">'; 116 117 $TableColumns = array( 118 array('Name' => 'Web', 'Title' => T('Address')), 119 array('Name' => 'MaxDateLast', 'Title' => T('Last visit')), 120 array('Name' => 'TotalHits', 'Title' => T('Hits')), 121 ); 122 if($this->System->User->Licence(LICENCE_ADMIN)) 123 { 124 $TableColumns[] = array('Name' => 'Visible', 'Title' => T('Visible')); 125 $TableColumns[] = array('Name' => 'Parent', 'Title' => T('Parent')); 126 $TableColumns[] = array('Name' => 'Description', 'Title' => T('Comment')); 127 127 $TableColumns[] = array('Name' => 'LastIP', 'Title' => T('Last IP address')); 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 128 $TableColumns[] = array('Name' => 'Action', 'Title' => T('Actions')); 129 } 130 $Order = GetOrderTableHeader($TableColumns, 'MaxDateLast', 1); 131 $Output .= $Order['Output']; 132 133 $Query .= $Order['SQL'].$PageList['SQLLimit']; 134 135 $DbResult = $this->Database->query($Query); 136 while($Line = $DbResult->fetch_assoc()) 137 { 138 $Output .= '<tr><td><a href="'.$Line['LastURL'].'">'.$Line['Web'].'</a></td>'. 139 '<td>'.HumanDate($Line['MaxDateLast']).'</td>'. 140 '<td>'.$Line['TotalHits'].'</td>'; 141 if($this->System->User->Licence(LICENCE_ADMIN)) 142 { 143 $Output .= 144 '<td>'.$YesNo[$Line['Visible']].'</td>'. 145 '<td>'.$Line['ParentName'].'</td>'. 146 '<td>'.$Line['Description'].'</td>'. 147 147 '<td>'.$Line['LastIP'].'</td>'. 148 148 '<td><a href="?action=edit&id='.$Line['Id'].'">'.T('Modify').'</a> '. 149 149 '<a href="?action=spam&id='.$Line['Id'].'">'.T('Spam').'</a></td>'; 150 151 152 153 154 155 150 } 151 $Output .= '</tr>'; 152 } 153 $Output .= '</table>'; 154 $Output .= $PageList['Output']; 155 return($Output); 156 156 } 157 157 … … 203 203 { 204 204 if($this->System->User->Licence(LICENCE_ADMIN)) 205 206 207 205 { 206 if(array_key_exists('id', $_GET)) 207 { 208 208 $DbResult = $this->Database->select('Referrer', '*', 'Id='.$_GET['id']); 209 210 211 212 213 214 215 216 217 218 209 if($DbResult->num_rows > 0) 210 { 211 $Item = $DbResult->fetch_assoc(); 212 if($Item['Visible'] == 1) $Visible = ' checked '; 213 else $Visible = ''; 214 $Output = '<form action="?action=editsave&id='.$_GET['id'].'" method="post"><table>'. 215 '<tr><td>'.T('Web').'</td><td>'.$Item['Web'].'</td></tr>'. 216 '<tr><td>'.T('Visible').'</td><td><input type="checkbox" name="Visible" '.$Visible.'/></td></tr>'. 217 '<tr><td>'.T('Description').'</td><td><input type="text" name="Description" value="'.$Item['Description'].'"/></td></tr>'. 218 '<tr><td>'.T('Parent item').'</td><td>'.$this->SelectParentItem($Item['Parent'], $Item['Id']).'</td></tr>'. 219 219 '<tr><td>'.T('Last IP address').'</td><td><input type="text" name="LastIP" value="'.$Item['LastIP'].'"/></td></tr>'. 220 221 222 223 224 220 '<tr><td colspan="2"><input type="submit" value="Uložit"/></td></tr></table></form>'; 221 } else $Output = ShowMessage(T('Item not found'), MESSAGE_CRITICAL); 222 } else $Output = ShowMessage(T('Item not specified'), MESSAGE_CRITICAL); 223 } else $Output = ShowMessage(T('Access denied'), MESSAGE_CRITICAL); 224 return($Output); 225 225 } 226 226 227 227 function EditSave() 228 228 { 229 230 231 232 233 234 235 236 237 229 if($this->System->User->Licence(LICENCE_ADMIN)) 230 { 231 if($_POST['Parent'] == '') $_POST['Parent'] = null; 232 $_POST['Visible'] = array_key_exists('Visible', $_POST); 233 $DbResult = $this->Database->update('Referrer', 'Id='.$_GET['id'], array( 234 'Visible' => $_POST['Visible'], 'LastIP' => $_POST['LastIP'], 235 'Parent' => $_POST['Parent'], 'Description' => $_POST['Description'])); 236 $_SERVER['QUERY_STRING'] = ''; 237 $Output = ShowMessage(T('Settings saved')); 238 238 $Output .= $this->ShowList(); 239 240 239 } else $Output = ShowMessage(T('Access denied'), MESSAGE_CRITICAL); 240 return($Output); 241 241 } 242 242 243 243 function Show() 244 244 { 245 245 $this->Title = T('Promotion'); 246 246 if(array_key_exists('action', $_GET)) 247 247 {
Note:
See TracChangeset
for help on using the changeset viewer.