Ignore:
Timestamp:
Feb 22, 2015, 11:20:50 PM (9 years ago)
Author:
chronos
Message:
  • Modified: Tabs converted to spaces.
  • Modified: Remove spaces from end of lines.
  • Added: Code format script.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Modules/Referrer/Referrer.php

    r811 r816  
    33class ModuleReferrer extends AppModule
    44{
    5         var $Excludes;
     5  var $Excludes;
    66
    77  function __construct($System)
     
    2020  function Start()
    2121  {
    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' => '',
     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' => '',
    3030    ));
    3131  }
     
    4040      if(!in_array($HostName, $this->Excludes))
    4141      {
    42         $IP = GetRemoteAddress();
     42        $IP = GetRemoteAddress();
    4343
    4444        // Check if client IP is not blaclisted as spam source. If yes then add new referrer as invisible
     
    6565        {
    6666          $this->System->Database->query('INSERT INTO `Referrer` (`Web`, `DateFirst`, `DateLast`, `LastURL`, `Hits`, `LastIP`, `Visible`, `Description`) '.
    67                   'VALUES ("'.$HostName.'", NOW(), NOW( ), "'.addslashes($Referrer).'", 1, "'.$IP.'", '.$Visible.', "'.$Description.'")');
     67          'VALUES ("'.$HostName.'", NOW(), NOW( ), "'.addslashes($Referrer).'", 1, "'.$IP.'", '.$Visible.', "'.$Description.'")');
    6868        }
    6969      }
     
    9393    $MonthAge = 3;
    9494    $YesNo = array('Ne', 'Ano');
    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'));
     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'));
    127127      $TableColumns[] = array('Name' => 'LastIP', 'Title' => T('Last IP address'));
    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>'.
     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>'.
    147147        '<td>'.$Line['LastIP'].'</td>'.
    148                         '<td><a href="?action=edit&amp;id='.$Line['Id'].'">'.T('Modify').'</a> '.
     148        '<td><a href="?action=edit&amp;id='.$Line['Id'].'">'.T('Modify').'</a> '.
    149149        '<a href="?action=spam&amp;id='.$Line['Id'].'">'.T('Spam').'</a></td>';
    150                 }
    151                 $Output .= '</tr>';
    152         }
    153         $Output .= '</table>';
    154         $Output .= $PageList['Output'];
    155         return($Output);
     150      }
     151      $Output .= '</tr>';
     152    }
     153    $Output .= '</table>';
     154    $Output .= $PageList['Output'];
     155    return($Output);
    156156  }
    157157
     
    203203  {
    204204    if($this->System->User->Licence(LICENCE_ADMIN))
    205           {
    206                 if(array_key_exists('id', $_GET))
    207                 {
     205    {
     206      if(array_key_exists('id', $_GET))
     207      {
    208208        $DbResult = $this->Database->select('Referrer', '*', 'Id='.$_GET['id']);
    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&amp;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>'.
     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&amp;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>'.
    219219            '<tr><td>'.T('Last IP address').'</td><td><input type="text" name="LastIP" value="'.$Item['LastIP'].'"/></td></tr>'.
    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);
     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);
    225225  }
    226226
    227227  function EditSave()
    228228  {
    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'));
     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'));
    238238      $Output .= $this->ShowList();
    239           } else $Output = ShowMessage(T('Access denied'), MESSAGE_CRITICAL);
    240           return($Output);
     239    } else $Output = ShowMessage(T('Access denied'), MESSAGE_CRITICAL);
     240    return($Output);
    241241  }
    242242
    243243  function Show()
    244244  {
    245         $this->Title = T('Promotion');
     245    $this->Title = T('Promotion');
    246246    if(array_key_exists('action', $_GET))
    247247    {
Note: See TracChangeset for help on using the changeset viewer.