Changeset 803 for trunk/Modules/Referrer/Referrer.php
- Timestamp:
- Apr 14, 2014, 8:29:20 PM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Modules/Referrer/Referrer.php
r766 r803 4 4 { 5 5 var $Excludes; 6 6 7 7 function __construct($System) 8 8 { … … 14 14 $this->Description = 'Log HTTP referrer URLs.'; 15 15 $this->Dependencies = array(); 16 16 17 17 $this->Excludes = array(); 18 18 } 19 19 20 20 function Start() 21 21 { … … 30 30 )); 31 31 } 32 32 33 33 function Log() 34 34 { 35 if(array_key_exists('HTTP_REFERER', $_SERVER)) 35 if(array_key_exists('HTTP_REFERER', $_SERVER)) 36 36 { 37 37 $Referrer = addslashes($_SERVER['HTTP_REFERER']); … … 40 40 if(!in_array($HostName, $this->Excludes)) 41 41 { 42 if(!isset($_SERVER['REMOTE_ADDR'])) $IP = 'Konzole'; 43 else $IP = addslashes($_SERVER['REMOTE_ADDR']); 44 45 // Check if client IP is not blocked as spam source 46 $DbResult = $this->System->Database->query('SELECT COUNT(*) FROM `Referrer` WHERE `LastIP` = "'.$IP.'" AND (`Visible` = 0)'); 47 $DbRow = $DbResult->fetch_row(); 48 if($DbRow[0] == 0) $Visible = '1'; 49 else $Visible = '0'; 50 51 // Check if host name is already stored and need just to update hit counter 42 52 $DbResult = $this->System->Database->query('SELECT `Id` FROM `Referrer` WHERE `Web` = "'.$HostName.'"'); 43 53 if($DbResult->num_rows > 0) … … 45 55 $DbRow = $DbResult->fetch_assoc(); 46 56 $this->System->Database->query('UPDATE `Referrer` SET `Hits` = `Hits` + 1, `DateLast` = NOW(), `LastURL` = "'. 47 addslashes($Referrer).'" WHERE `Id` = '.$DbRow['Id']);48 } else $this->System->Database->query('INSERT INTO `Referrer` (`Web`, `DateFirst`, `DateLast`, `LastURL`, `Hits` ) '.49 'VALUES ("'.$HostName.'", NOW(), NOW( ), "'.addslashes($Referrer).'", 1)');57 addslashes($Referrer).'", `LastIP` = "'.$IP.'" WHERE `Id` = '.$DbRow['Id']); 58 } else $this->System->Database->query('INSERT INTO `Referrer` (`Web`, `DateFirst`, `DateLast`, `LastURL`, `Hits`, `LastIP`, `Visible`) '. 59 'VALUES ("'.$HostName.'", NOW(), NOW( ), "'.addslashes($Referrer).'", 1, "'.$IP.'", '.$Visible.')'); 50 60 } 51 61 } 52 } 62 } 53 63 } 54 64 55 65 class PageReferrer extends Page 56 66 { … … 61 71 'alt="wowpreklad" title="Otevřený projekt překládání celé hry World of Warcraft" '. 62 72 'class="banner" height="60" width="468" /></a>'; 63 73 64 74 $BannerSmall = '<a href="http://'.$this->System->Config['Web']['Host'].$this->System->Link('/').'">'. 65 75 '<img src="http://'.$this->System->Config['Web']['Host'].$this->System->Link('/banners/wowpreklad_small.jpg').'" '. … … 68 78 69 79 $Output = '<strong>'.T('Banners').':</strong><br />'; 70 80 71 81 $Output .= $Banner.' <textarea rows="2" cols="30">'.htmlspecialchars($Banner).'</textarea><br />'; 72 82 $Output .= $BannerSmall.' <textarea rows="2" cols="30">'.htmlspecialchars($BannerSmall).'</textarea><br />'; 73 83 74 84 $MonthAge = 3; 75 85 $YesNo = array('Ne', 'Ano'); 76 86 $Output .= '<br/><strong>'.T('Servers referring to us').':</strong> <br /> 77 <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 />'; 78 79 if(!$this->System->User->Licence(LICENCE_ADMIN)) $Where = ' WHERE (` Show`=1) AND (`Parent` IS NULL)';87 <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 />'; 88 89 if(!$this->System->User->Licence(LICENCE_ADMIN)) $Where = ' WHERE (`Visible`=1) AND (`Parent` IS NULL)'; 80 90 else $Where = ''; 81 91 $Query = 'SELECT *, (SELECT Web FROM `Referrer` AS T4 WHERE T4.Id = T3.Parent) AS ParentName '. … … 87 97 '`Referrer` AS `T2` '.$Where.') AS `T3` '. 88 98 'WHERE (`T3`.`MaxDateLast` > (NOW() - INTERVAL '.$MonthAge.' MONTH))'; 89 90 99 100 91 101 $DbResult = $this->Database->query('SELECT COUNT(*) FROM ('.$Query.') AS T'); 92 102 $DbRow = $DbResult->fetch_row(); 93 103 $PageList = GetPageList($DbRow[0]); 94 104 95 105 $Output .= $PageList['Output']. 96 106 '<table class="BaseTable">'; 97 107 98 108 $TableColumns = array( 99 109 array('Name' => 'Web', 'Title' => T('Address')), … … 103 113 if($this->System->User->Licence(LICENCE_ADMIN)) 104 114 { 105 $TableColumns[] = array('Name' => ' Show', 'Title' => T('Visible'));115 $TableColumns[] = array('Name' => 'Visible', 'Title' => T('Visible')); 106 116 $TableColumns[] = array('Name' => 'Parent', 'Title' => T('Parent')); 107 117 $TableColumns[] = array('Name' => 'Description', 'Title' => T('Comment')); 118 $TableColumns[] = array('Name' => 'LastIP', 'Title' => T('Last IP address')); 108 119 $TableColumns[] = array('Name' => 'Action', 'Title' => T('Actions')); 109 120 } 110 121 $Order = GetOrderTableHeader($TableColumns, 'MaxDateLast', 1); 111 122 $Output .= $Order['Output']; 112 123 113 124 $Query .= $Order['SQL'].$PageList['SQLLimit']; 114 125 115 126 $DbResult = $this->Database->query($Query); 116 127 while($Line = $DbResult->fetch_assoc()) … … 122 133 { 123 134 $Output .= 124 '<td>'.$YesNo[$Line[' Show']].'</td>'.135 '<td>'.$YesNo[$Line['Visible']].'</td>'. 125 136 '<td>'.$Line['ParentName'].'</td>'. 126 137 '<td>'.$Line['Description'].'</td>'. 127 '<td><a href="?action=edit&id='.$Line['Id'].'">'.T('Modify').'</a></td>'; 138 '<td>'.$Line['LastIP'].'</td>'. 139 '<td><a href="?action=edit&id='.$Line['Id'].'">'.T('Modify').'</a> '. 140 '<a href="?action=spam&id='.$Line['Id'].'">'.T('Spam').'</a></td>'; 128 141 } 129 142 $Output .= '</tr>'; … … 131 144 $Output .= '</table>'; 132 145 $Output .= $PageList['Output']; 133 return($Output); 146 return($Output); 134 147 } 135 148 … … 154 167 } 155 168 169 function Spam() 170 { 171 if($this->System->User->Licence(LICENCE_ADMIN)) 172 { 173 if(array_key_exists('id', $_GET)) 174 { 175 $DbResult = $this->Database->select('Referrer', '*', 'Id='.$_GET['id']); 176 if($DbResult->num_rows > 0) 177 { 178 $Item = $DbResult->fetch_assoc(); 179 $this->Database->update('Referrer', 'Id='.$_GET['id'], array('Visible' => 0, 'Description' => 'Spam')); 180 $Output = ShowMessage(T('Set as spam'), MESSAGE_CRITICAL); 181 $Output .= $this->ShowList(); 182 } else $Output = ShowMessage(T('Item not found'), MESSAGE_CRITICAL); 183 } else $Output = ShowMessage(T('Item not specified'), MESSAGE_CRITICAL); 184 } else $Output = ShowMessage(T('Access denied'), MESSAGE_CRITICAL); 185 return($Output); 186 } 187 156 188 function Edit() 157 189 { … … 164 196 { 165 197 $Item = $DbResult->fetch_assoc(); 166 if($Item[' Show'] == 1) $Show= ' checked ';167 else $ Show= '';198 if($Item['Visible'] == 1) $Visible = ' checked '; 199 else $Visible = ''; 168 200 $Output = '<form action="?action=editsave&id='.$_GET['id'].'" method="post"><table>'. 169 201 '<tr><td>'.T('Web').'</td><td>'.$Item['Web'].'</td></tr>'. 170 '<tr><td>'.T('Visible').'</td><td><input type="checkbox" name=" Show" '.$Show.'/></td></tr>'.202 '<tr><td>'.T('Visible').'</td><td><input type="checkbox" name="Visible" '.$Visible.'/></td></tr>'. 171 203 '<tr><td>'.T('Description').'</td><td><input type="text" name="Description" value="'.$Item['Description'].'"/></td></tr>'. 172 204 '<tr><td>'.T('Parent item').'</td><td>'.$this->SelectParentItem($Item['Parent'], $Item['Id']).'</td></tr>'. 205 '<tr><td>'.T('Last IP address').'</td><td><input type="text" name="LastIP" value="'.$Item['LastIP'].'"/></td></tr>'. 173 206 '<tr><td colspan="2"><input type="submit" value="Uložit"/></td></tr></table></form>'; 174 207 } else $Output = ShowMessage(T('Item not found'), MESSAGE_CRITICAL); … … 181 214 { 182 215 if($this->System->User->Licence(LICENCE_ADMIN)) 183 { 216 { 184 217 if($_POST['Parent'] == '') $_POST['Parent'] = null; 185 $_POST[' Show'] = array_key_exists('Show', $_POST);218 $_POST['Visible'] = array_key_exists('Visible', $_POST); 186 219 $DbResult = $this->Database->update('Referrer', 'Id='.$_GET['id'], array( 187 'Show' => $_POST['Show'], 220 'Visible' => $_POST['VisNadřazená položka 221 Last IP address ible'], 'LastIP' => $_POST['LastIP'], 188 222 'Parent' => $_POST['Parent'], 'Description' => $_POST['Description'])); 189 223 $_SERVER['QUERY_STRING'] = ''; … … 200 234 { 201 235 if($_GET['action'] == 'edit') $Output = $this->Edit(); 236 else if($_GET['action'] == 'spam') $Output = $this->Spam(); 202 237 else if($_GET['action'] == 'editsave') $Output = $this->EditSave(); 203 else $Output = $this->ShowList(); 238 else $Output = $this->ShowList(); 204 239 } else $Output = $this->ShowList(); 205 240 return($Output);
Note:
See TracChangeset
for help on using the changeset viewer.