Changeset 4


Ignore:
Timestamp:
Aug 5, 2018, 1:12:12 AM (6 years ago)
Author:
chronos
Message:
  • Added: RSS channel.
  • Added: Location and weight properties.
  • Modified: Better sorting and paging of table.
  • Added: Filtering by gender.
Location:
trunk
Files:
2 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Meet.php

    r3 r4  
    148148  $Result = GetNumberBeforeText($Text, 'let');
    149149  if ($Result == '') $Result = GetNumberAfterText($Text, 'Je mi');
     150  if ($Result == '') $Result = GetAgeHeightWeightFromText($Text)[0];
    150151  return $Result;
    151152}
     
    155156  $Result = GetNumberBeforeText($Text, 'cm');
    156157  if ($Result == '') $Result = GetNumberBeforeText($Text, 'bez podpatků'); 
     158  if ($Result == '') $Result = GetAgeHeightWeightFromText($Text)[1];
    157159  return $Result;
    158160}
     
    161163{
    162164  $Result = GetNumberBeforeText($Text, 'kg');
     165  if ($Result == '') $Result = GetAgeHeightWeightFromText($Text)[2];
     166  return $Result;
     167}
     168
     169function GetAgeHeightWeightFromText($Text)
     170{
     171  $Result = array('', '', '');
     172  $Pattern = '/[0-9]+\/[0-9]+\/[0-9]+/i';
     173  if (preg_match_all($Pattern, $Text, $Matches))
     174  {
     175    $Result = explode('/', $Matches[0][0]);
     176  } else
     177  {
     178    $Pattern = '/[0-9]+\/[0-9]+/i';
     179    if (preg_match_all($Pattern, $Text, $Matches))
     180    {
     181      $Result = explode('/', $Matches[0][0]);
     182      $Result[] = '';
     183    }
     184  }
    163185  return $Result;
    164186}
     
    282304      if (strpos($MeetItem->Date, 'dnes v') !== false)
    283305        $MeetItem->Date = str_replace('dnes v', HumanDate(time()), $MeetItem->Date);
     306      if (strpos($MeetItem->Date, 'včera v') !== false)
     307        $MeetItem->Date = str_replace('včera v', HumanDate(strtotime('-1 day', time())), $MeetItem->Date);
    284308      $MeetItem->Date = HumanDateTimeToTime($MeetItem->Date);
    285309      $MeetItem->Name = trim(GetTextBetween($Item, '<div class="comment-name">', '</div>'));
     
    293317      $MeetItem->Database = $this->Database;
    294318      $MeetItem->Source = $this->Id;
     319      //print_r($MeetItem);
    295320      $MeetItem->AddIfNotExist();
    296321    }
     
    338363  function ParseHes()
    339364  {
     365    $HeightRange = array(
     366      '< 120 cm' => 120,
     367      '120 cm - 130 cm' => 125,
     368      '125 cm - 135 cm' => 130,
     369      '130 cm - 140 cm' => 135,
     370      '135 cm - 145 cm' => 140,
     371      '140 cm - 150 cm' => 145,
     372      '145 cm - 155 cm' => 150,
     373      '150 cm - 160 cm' => 155,
     374      '155 cm - 165 cm' => 160,
     375      '160 cm - 170 cm' => 165,
     376      '165 cm - 175 cm' => 170,
     377      '170 cm - 180 cm' => 175,
     378      '175 cm - 185 cm' => 180,
     379      '180 cm - 190 cm' => 185,
     380      '185 cm - 195 cm' => 190,
     381      '190 cm - 200 cm' => 195,
     382      '195 cm - 205 cm' => 200,
     383      '200 cm <' => 205,
     384    );
     385   
    340386    echo('Parsing '.$this->Name.'...</br>');
    341387    $Content = file_get_contents($this->URL);   
     
    358404      if ($Item != '')
    359405      {
    360          $MeetItem = new MeetItem();
    361          $MeetItem->Date = HumanDateToTime(trim(GetTextBetween($Item, '<h3>', '</h3>')));
    362          if ($MeetItem->Date != null)
    363          {
    364            $PreviousTime = $MeetItem->Date;
    365          } else $MeetItem->Date = $PreviousTime;           
    366          
    367          $Part = GetTextBetween($Item, '</strong>', '<strong>');
    368          $Part = explode(',', $Part);
    369          if (count($Part) > 0) $MeetItem->Name = trim($Part[0]);
    370          if (count($Part) > 1) $MeetItem->Height = trim($Part[1]);
    371          if (strpos($MeetItem->Height, '(') !== false)
    372          {
    373            $MeetItem->Age = substr($MeetItem->Height, strpos($MeetItem->Height, '(') + 1);
    374            $MeetItem->Age = substr($MeetItem->Age, 0, strpos($MeetItem->Age, ')'));
    375            $MeetItem->Age = trim(str_replace('let', '', $MeetItem->Age));
    376            $MeetItem->Height = substr($MeetItem->Height, 0, strpos($MeetItem->Height, '('));
    377          } else $MeetItem->Age = '';
    378          $MeetItem->Weight = GetWeightFromText($MeetItem->Message);
    379          $MeetItem->Email = trim(GetTextBetween($Item, '">', '</a>'));
    380          $MeetItem->Phone = trim(GetTextBetween($Item, 'tel.:', '<br />'));
    381          $Gender = trim(GetTextBetween($Item, '</strong>', '<strong>'));
    382          if ($Gender == 'partnera,') $MeetItem->Gender = Gender::Female;
    383            else if ($Gender == 'partnerku,') $MeetItem->Gender = Gender::Male;
    384            else $MeetItem->Gender = Gender::Undefined;
    385          $MeetItem->Message = trim(GetTextBetween($Item, '<p class="message">', '</p>'));       
    386          $MessageAge = GetAgeFromText($MeetItem->Message);
    387          if ($MessageAge != '') $MeetItem->Age = $MessageAge;
    388          $MessageHeight = GetHeightFromText($MeetItem->Message);
    389          if ($MessageHeight != '') $MeetItem->Height = $MessageHeight;
    390          $MeetItem->Database = $this->Database;
    391          $MeetItem->Source = $this->Id;
    392          $MeetItem->AddIfNotExist();
     406        $MeetItem = new MeetItem();
     407        $MeetItem->Date = HumanDateToTime(trim(GetTextBetween($Item, '<h3>', '</h3>')));
     408        if ($MeetItem->Date != null)
     409        {
     410          $PreviousTime = $MeetItem->Date;
     411        } else $MeetItem->Date = $PreviousTime;           
     412       
     413        $Part = GetTextBetween($Item, '</strong>', '<strong>');
     414        $Part = explode(',', $Part);
     415        if (count($Part) > 0) $MeetItem->Name = trim($Part[0]);
     416        if (count($Part) > 1) $MeetItem->Height = trim($Part[1]);
     417        if (strpos($MeetItem->Height, '(') !== false)
     418        {
     419          $MeetItem->Age = substr($MeetItem->Height, strpos($MeetItem->Height, '(') + 1);
     420          $MeetItem->Age = substr($MeetItem->Age, 0, strpos($MeetItem->Age, ')'));
     421          $MeetItem->Age = trim(str_replace('let', '', $MeetItem->Age));
     422          $MeetItem->Height = trim(substr($MeetItem->Height, 0, strpos($MeetItem->Height, '(')));
     423        } else $MeetItem->Age = '';
     424        while (strpos($MeetItem->Height, '  ') !== false)
     425        {
     426          $MeetItem->Height = str_replace('  ', ' ', $MeetItem->Height);
     427        }
     428        if (array_key_exists($MeetItem->Height, $HeightRange))
     429          $MeetItem->Height = $HeightRange[$MeetItem->Height];
     430        $MeetItem->Weight = GetWeightFromText($MeetItem->Message);
     431        $MeetItem->Email = trim(GetTextBetween($Item, '">', '</a>'));
     432        $MeetItem->Phone = trim(GetTextBetween($Item, 'tel.:', '<br />'));
     433        $Gender = trim(GetTextBetween($Item, '</strong>', '<strong>'));
     434        if ($Gender == 'partnera,') $MeetItem->Gender = Gender::Female;
     435          else if ($Gender == 'partnerku,') $MeetItem->Gender = Gender::Male;
     436          else $MeetItem->Gender = Gender::Undefined;
     437        $MeetItem->Message = trim(GetTextBetween($Item, '<p class="message">', '</p>'));       
     438        $MessageAge = GetAgeFromText($MeetItem->Message);
     439        if ($MessageAge != '') $MeetItem->Age = $MessageAge;
     440        $MessageHeight = GetHeightFromText($MeetItem->Message);
     441        if ($MessageHeight != '') $MeetItem->Height = $MessageHeight;
     442        $MeetItem->Database = $this->Database;
     443        $MeetItem->Source = $this->Id;
     444        $MeetItem->AddIfNotExist();
    393445      }     
    394446    }   
  • trunk/index.php

    r3 r4  
    44include_once('Config.php');
    55include_once('Meet.php');
     6include_once('RSS.php');
     7include_once('Global.php');
    68
    79session_start();
    810
    9 function HumanDate($Time)
    10 {
    11   return(date('j.n.Y', $Time));
    12 }
    13  
    1411class Application
    1512{
     13  var $NoFullPage = false;
     14 
    1615  function Link($URL)
    1716  {
     
    6968      $Output .= '<th>'.$ResourceGroup['Name'].'</th>';
    7069    }
    71     $Output .= '</tr>';
     70    $Output .= '</tr>';     
    7271    $DbResult = $this->Database->select('Dance', '*, (SELECT Name FROM DanceGroup WHERE DanceGroup.Id=Dance.Group) AS GroupName', '1 ORDER BY `Name`');
    7372    while($Dance = $DbResult->fetch_assoc())
     
    118117  function ShowMeetList()
    119118  {
     119    $Output = '';
     120    //print_r($_GET);
    120121    if (array_key_exists('lvm', $_GET) and ($_GET['lvm'] == 'seznam'))
    121122    {
     
    125126      if (array_key_exists('vyskaod', $_GET) ) $_SESSION['vyskaod'] = $_GET['vyskaod'];
    126127      if (array_key_exists('vyskado', $_GET) ) $_SESSION['vyskado'] = $_GET['vyskado'];
     128      if (array_key_exists('vahaod', $_GET) ) $_SESSION['vahaod'] = $_GET['vahaod'];
     129      if (array_key_exists('vahado', $_GET) ) $_SESSION['vahado'] = $_GET['vahado'];
     130      if (array_key_exists('pohlavi', $_GET) ) {
     131        if ($_GET['pohlavi'] > 0) $_SESSION['pohlavi'] = $_GET['pohlavi'];
     132          else unset($_SESSION['pohlavi']);
     133      }
    127134    } else {
    128     $Output = '';
    129135    $Output .= '<script>function reloadlist(){ $(\'#meetlist\').load(document.URL + \' #meetlist\');}'.
    130136      ' var load_timer = 100;
     
    143149   }
    144150           
    145    var cf = {pohlavi:\'2\'};
     151   var cf = {};
    146152
    147153   function setupc(key,val){
     
    150156         var ccv = $(\'#\'+key).val();
    151157         if(ccv!=val) $(\'#\'+key).val(val==0?\'\':val);
     158      }
     159      if(key==\'pohlavi\') {
     160         $(\'.c\'+key).removeClass(\'active\');
     161         $(\'#\'+key+val).addClass(\'active\');
    152162      }
    153163   }
     
    167177   }'.
    168178      '</script>';
     179    $Output .= '<h4 style="text-align: center;">Inzeráty:</h4>';
     180    $Output .= '<div class="btn-group ma3">'.
     181      '<button class="btn btn-filter cpohlavi btn-ico" onclick="upf(\'pohlavi\',0)" id="pohlavi0" data-toggle="tooltip" '.
     182      'data-placement="top" title="Obě pohlaví"><span class="icon-both"></span></button>'.
     183      '<button class="btn btn-filter cpohlavi btn-ico" onclick="upf(\'pohlavi\',1)" id="pohlavi1" data-toggle="tooltip" '.
     184      'data-placement="top" title="Jen muži"><span class="icon-man"></span></button>'.
     185      '<button class="btn btn-filter cpohlavi btn-ico" onclick="upf(\'pohlavi\',2)" id="pohlavi2" data-toggle="tooltip" '.
     186      'data-placement="top" title="Jen ženy"><span class="icon-woman"></span></button>'.
     187      '</div>';
    169188    $Output .= '<div class="filter-num-box">'.
    170189      '<div class="label-box">Věk</div>'.
    171       '<input value="" onkeyup="if(event.keyCode!=9) upf(\'vekod\',$(this).val(),(event.keyCode==13?0:1)); '.
     190      '<input value="'.$_SESSION['vekod'].'" onkeyup="if(event.keyCode!=9) upf(\'vekod\',$(this).val(),(event.keyCode==13?0:1)); '.
    172191      '" id="vekod" autocomplete="off" type="text">'.
    173192      '<div class="label-box">-</div>'.
    174       '<input value="" onkeyup="'.
     193      '<input value="'.$_SESSION['vekdo'].'" onkeyup="'.
    175194      'if(event.keyCode!=9) upf(\'vekdo\',$(this).val(),(event.keyCode==13?0:1));" '.
    176195      'id="vekdo" autocomplete="off" type="text"><div class="label-box">let</div></div>'.
    177       '</div> '.
    178       '<div class="filter-num-box">'.
     196      '</div> ';
     197    $Output .= '<div class="filter-num-box">'.
    179198      '<div class="label-box">Výška</div>'.
    180       '<input value="" onkeyup="if(event.keyCode!=9) upf(\'vyskaod\',$(this).val(),(event.keyCode==13?0:1)); '.
     199      '<input value="'.$_SESSION['vyskaod'].'" onkeyup="if(event.keyCode!=9) upf(\'vyskaod\',$(this).val(),(event.keyCode==13?0:1)); '.
    181200      '" id="vyskaod" autocomplete="off" type="text">'.
    182201      '<div class="label-box">-</div>'.
    183       '<input value="" onkeyup="'.
     202      '<input value="'.$_SESSION['vyskado'].'" onkeyup="'.
    184203      'if(event.keyCode!=9) upf(\'vyskado\',$(this).val(),(event.keyCode==13?0:1));" '.
    185204      'id="vyskado" autocomplete="off" type="text"><div class="label-box">cm</div></div>'.
     205      '</div> ';
     206    $Output .= '<div class="filter-num-box">'.
     207      '<div class="label-box">Váha</div>'.
     208      '<input value="'.$_SESSION['vahaod'].'" onkeyup="if(event.keyCode!=9) upf(\'vahaod\',$(this).val(),(event.keyCode==13?0:1)); '.
     209      '" id="vahaod" autocomplete="off" type="text">'.
     210      '<div class="label-box">-</div>'.
     211      '<input value="'.$_SESSION['vahado'].'" onkeyup="'.
     212      'if(event.keyCode!=9) upf(\'vahado\',$(this).val(),(event.keyCode==13?0:1));" '.
     213      'id="vahado" autocomplete="off" type="text"><div class="label-box">cm</div></div>'.
    186214      '</div>';
    187       $Output .= '<h4 style="text-align: center;">Inzeráty:</h4>';
    188     }
    189    
    190     $Gender = array('', 'Muž', 'Žena');
    191     $Output .= '<div id="list_content">'.
    192       '<table class="WideTable">';
    193     $Output .= '<tr>'.
    194       '<th>Datum</th>'.
    195       '<th>Jméno</th>'.
    196       '<th>Výška</th>'.
    197       '<th>Věk</th>'.
    198       '<th>Váha</th>'.
    199       //'<th>Email</th>'.
    200       //'<th>Telefon</th>'.
    201       '<th>Pohlaví</th>'.
    202       '<th>Zpráva</th>'.
    203       '<th>Zdroj</th>';
    204     $Output .= '</tr>';
     215    }
     216   
    205217    $Where = '';   
    206218    if (array_key_exists('vekod', $_SESSION) and ($_SESSION['vekod'] != '')) $Where .= ' AND (Age >= '.$_SESSION['vekod'].')';
     
    208220    if (array_key_exists('vyskaod', $_SESSION) and ($_SESSION['vyskaod'] != '')) $Where .= ' AND (Height >= '.$_SESSION['vyskaod'].')';
    209221    if (array_key_exists('vyskado', $_SESSION) and ($_SESSION['vyskado'] != '')) $Where .= ' AND (Height <= '.$_SESSION['vyskado'].')';
     222    if (array_key_exists('vahaod', $_SESSION) and ($_SESSION['vahaod'] != '')) $Where .= ' AND (Weight >= '.$_SESSION['vahaod'].')';
     223    if (array_key_exists('vahado', $_SESSION) and ($_SESSION['vahado'] != '')) $Where .= ' AND (Weight <= '.$_SESSION['vahado'].')';
     224    if (array_key_exists('pohlavi', $_SESSION) and ($_SESSION['pohlavi'] != '')) $Where .= ' AND (Gender = '.$_SESSION['pohlavi'].')';
    210225    if (substr($Where, 0, 4) == ' AND') $Where = substr($Where, 4);
    211     if ($Where == '') $Where = '1';
     226    if ($Where == '') $Where = '1';   
     227   
     228    $DbResult = $this->Database->query('SELECT COUNT(*) FROM `MeetItem` WHERE '.$Where);
     229    $DbRow = $DbResult->fetch_row();
     230    $PageList = GetPageList($DbRow[0]);
     231   
     232    $Gender = array('', 'Muž', 'Žena');
     233    $Output .= '<div id="list_content">';
     234    $Output .= $PageList['Output'];
     235    $TableColumns = array(
     236      array('Name' => 'Date', 'Title' => 'Datum'),
     237      array('Name' => 'Name', 'Title' => 'Jméno'),
     238      array('Name' => 'Height', 'Title' => 'Výška'),
     239      array('Name' => 'Age', 'Title' => 'Věk'),
     240      array('Name' => 'Weight', 'Title' => 'Váha'),
     241      array('Name' => 'Gender', 'Title' => 'Pohlaví'),
     242      array('Name' => 'Message', 'Title' => 'Zpráva'),
     243      array('Name' => 'Source', 'Title' => 'Zdroj'),
     244    );
     245    $Order = GetOrderTableHeader($TableColumns, 'Date', 1);
     246    $Output .= '<table class="WideTable">';
     247    $Output .= $Order['Output'];
    212248    $DbResult = $this->Database->select('MeetItem', '*, (SELECT MeetSource.Name FROM MeetSource WHERE MeetSource.Id = MeetItem.Source) AS SourceName, '.
    213       '(SELECT MeetSource.URL FROM MeetSource WHERE MeetSource.Id = MeetItem.Source) AS SourceURL', $Where.' ORDER BY `Date` DESC');
     249      '(SELECT MeetSource.URL FROM MeetSource WHERE MeetSource.Id = MeetItem.Source) AS SourceURL', $Where.$Order['SQL'].$PageList['SQLLimit']);
    214250    while($MeetItem = $DbResult->fetch_assoc())
    215251    {
     
    227263      $Output .= '</tr>';
    228264    }
    229     $Output .= '</table></div>';
    230 
    231     return($Output);
     265    $Output .= '</table>';
     266    $Output .= $PageList['Output'];
     267    $Output .= '</div>';
     268
     269    return($Output);
     270  }
     271 
     272  function ShowMeetListRss()
     273  {
     274    global $Config;
     275   
     276    $this->NoFullPage = true;
     277    $RSS = new RSS();
     278    $RSS->Title = 'Taneční seznamka';
     279    $RSS->Description = '';
     280    $RSS->Link = $Config['BaseURL'].'seznamka';
     281   
     282    $DbResult = $this->Database->select('MeetItem', '*, (SELECT MeetSource.Name FROM MeetSource WHERE MeetSource.Id = MeetItem.Source) AS SourceName, '.
     283      '(SELECT MeetSource.URL FROM MeetSource WHERE MeetSource.Id = MeetItem.Source) AS SourceURL', '1 ORDER BY `Date` DESC LIMIT 30');
     284    while($MeetItem = $DbResult->fetch_assoc())
     285    {
     286      $Title = $MeetItem['Name'];
     287      if ($MeetItem['Age'] != '') $Title .= ', '.$MeetItem['Age'].' let';
     288      if ($MeetItem['Weight'] != '') $Title .= ', '.$MeetItem['Height'].' cm';
     289      $Description = $MeetItem['Message'];
     290      if ($MeetItem['Email'] != '') $Description .= '<br/>Email: '.$MeetItem['Email'];
     291      if ($MeetItem['Phone'] != '') $Description .= '<br/>Telefon: '.$MeetItem['Phone'];
     292      $Description .= '<br/>Škola: <a href="'.$this->Link($MeetItem['SourceURL']).'">'.$MeetItem['SourceName'].'</a>';
     293      $RSS->Items[] = array(         
     294        'Title' => $Title,
     295        'Description' => $Description,
     296        'Time' => MysqlDateTimeToTime($MeetItem['Date']),
     297        'Link' => $Config['BaseURL'].'seznamka',
     298      );
     299      $Output .= '<tr>'.
     300        '<td>'.HumanDate(MysqlDateToTime($MeetItem['Date'])).'</td>'.
     301        '<td>'.$MeetItem['Name'].'</td>'.
     302        '<td>'.$MeetItem['Height'].'</td>'.
     303        '<td>'.$MeetItem['Age'].'</td>'.
     304        '<td>'.$MeetItem['Weight'].'</td>'.
     305        //'<td>'.$MeetItem['Email'].'</td>'.
     306        //'<td>'.$MeetItem['Phone'].'</td>'.
     307        '<td>'.$Gender[$MeetItem['Gender']].'</td>'.
     308        '<td>'.$MeetItem['Message'].'</td>'.
     309        '<td></td>';
     310      $Output .= '</tr>';
     311    }
     312
     313    return $RSS->Generate();
    232314  }
    233315
     
    240322      '<link rel="stylesheet" href="'.$this->Link('/style.css').'" type="text/css" media="all" />'.
    241323      '<meta http-equiv="content-type" content="application/xhtml+xml; charset='.$this->Config['Encoding'].'" />'.
    242       '<script src="jquery.js"></script>'.
    243       '<title>Tance</title>'.
     324      '<script src="jquery.js"></script>';
     325    $Output .= '<link rel="alternate" title="Taneční seznamka" href="'.
     326      $this->Config['BaseURL'].'seznamka-rss" type="application/rss+xml" />';
     327    $Output .= '<title>Tance</title>'.
    244328      '</head><body>';
    245329    $Output .= $Content;
     
    266350      else if($this->PathItems[0] == 'tance') $Output .= $this->ShowDanceList();
    267351      else if($this->PathItems[0] == 'seznamka') $Output .= $this->ShowMeetList();
     352      else if($this->PathItems[0] == 'seznamka-rss') $Output .= $this->ShowMeetListRss();
    268353      else if($this->PathItems[0] == 'seznamka-aktualizace') $Output .= $this->ShowMeetUpdate();
    269354      else $Output .= $this->ShowDanceList();
  • trunk/style.css

    r3 r4  
     1body,td{font-size:14px;font-family:Arial}
     2
    13.WideTable
    24{
     
    4850.filter-num-box div.dropdown .btn{background:#fff;margin:0;border:0;padding:0 8px;line-height:28px;font-size:13px;border-radius: 0}
    4951.filter-num-box div.dropdown-menu a.dropdown-item{line-height:20px;font-size:13px}
     52
     53.icon-both:before {
     54  content: "Obě";
     55  color: black;
     56}
     57.icon-woman:before {
     58  content: "Ženy";
     59  color: black;
     60}
     61.icon-man:before {
     62  content: "Muži";
     63  color: black;
     64}
Note: See TracChangeset for help on using the changeset viewer.