コード例 #1
0
 function testFetch()
 {
     $time = mktime(6, 0, 0, 3, 6, 2005);
     $day = 24 * 60 * 60;
     $toolkit =& Limb::toolkit();
     $db_table =& $toolkit->createDBTable('StatsUri');
     $db_table->insert(array('id' => $uri_id1 = 1, 'uri' => $uri1 = '/news'));
     $db_table->insert(array('id' => $uri_id2 = 2, 'uri' => $uri2 = '/articles'));
     $db_table =& $toolkit->createDBTable('StatsHit');
     $db_table->insert(array('stats_referer_id' => 1, 'session_id' => 'any', 'stats_uri_id' => $uri_id1, 'action' => 'any', 'time' => $time1 = $time, 'ip' => $ip = Ip::encode('192.168.0.1')));
     $db_table->insert(array('stats_referer_id' => 1, 'session_id' => 'any', 'stats_uri_id' => $uri_id1, 'action' => 'any', 'time' => $time2 = $time + $day, 'ip' => $ip));
     $db_table->insert(array('stats_referer_id' => 1, 'session_id' => 'any', 'stats_uri_id' => $uri_id1, 'action' => 'any', 'time' => $time3 = $time + $day, 'ip' => $ip));
     $db_table->insert(array('stats_referer_id' => 1, 'session_id' => 'any', 'stats_uri_id' => $uri_id2, 'action' => 'any', 'time' => $time4 = $time + 2 * $day, 'ip' => $ip));
     $db_table->insert(array('stats_referer_id' => 1, 'session_id' => 'any', 'stats_uri_id' => $uri_id1, 'action' => 'any', 'time' => $time5 = $time + 3 * $day, 'ip' => $ip));
     $request =& $toolkit->getRequest();
     $request->set('start_date', date('Y-m-d', $time2));
     $request->set('finish_date', date('Y-m-d', $time5));
     // Must find three records only
     $dao = new StatsPagesReportDAO();
     $rs =& $dao->fetch();
     $this->assertTrue(is_a($rs, 'StatsPercentageRecordSet'));
     $this->assertEqual($rs->getRowCount(), 2);
     $rs->rewind();
     $record =& $rs->current();
     $this->assertEqual($record->get('uri'), $uri1);
     $rs->next();
     $record =& $rs->current();
     $this->assertEqual($record->get('uri'), $uri2);
 }
コード例 #2
0
 function testFetch()
 {
     $time = mktime(6, 0, 0, 3, 6, 2005);
     $day = 24 * 60 * 60;
     $toolkit =& Limb::toolkit();
     $db_table =& $toolkit->createDBTable('StatsHit');
     $db_table->insert(array('stats_referer_id' => 1, 'session_id' => 'any', 'stats_uri_id' => 1, 'action' => 'any', 'time' => $time1 = $time, 'ip' => $ip1 = Ip::encode('192.168.0.1')));
     $db_table->insert(array('stats_referer_id' => 1, 'session_id' => 'any', 'stats_uri_id' => 1, 'action' => 'any', 'time' => $time2 = $time + $day, 'ip' => $ip1));
     $db_table->insert(array('stats_referer_id' => 1, 'session_id' => 'any', 'stats_uri_id' => 1, 'action' => 'any', 'time' => $time3 = $time + $day, 'ip' => $ip2 = Ip::encode('192.168.0.2')));
     $db_table->insert(array('stats_referer_id' => 1, 'session_id' => 'any', 'stats_uri_id' => 1, 'action' => 'any', 'time' => $time4 = $time + 2 * $day, 'ip' => $ip1));
     $db_table->insert(array('stats_referer_id' => 1, 'session_id' => 'any', 'stats_uri_id' => 1, 'action' => 'any', 'time' => $time5 = $time + 3 * $day, 'ip' => $ip1));
     $request =& $toolkit->getRequest();
     $request->set('start_date', date('Y-m-d', $time2));
     $request->set('finish_date', date('Y-m-d', $time4));
     // Must find three records only
     $dao = new StatsHitsReportDAO();
     $rs =& $dao->fetch();
     $this->assertEqual($rs->getRowCount(), 3);
     $rs->rewind();
     $record =& $rs->current();
     $this->assertEqual($record->get('ip'), $ip1);
     $this->assertEqual($record->get('stats_referer_id'), 1);
     $this->assertEqual($record->get('session_id'), 'any');
     $this->assertEqual($record->get('action'), 'any');
     $this->assertEqual($record->get('time'), $time2);
 }
コード例 #3
0
 function _checkStatsIpRecord($total_records, $ip, $time)
 {
     $encoded_ip = Ip::encode($ip);
     $rs =& $this->db->select('stats_ip');
     $arr = $rs->getArray('id');
     $this->assertTrue(sizeof($arr), $total_records, 'ip count is wrong');
     $this->assertTrue(isset($arr[$encoded_ip]));
     $this->assertEqual($arr[$encoded_ip]['time'], $time, 'ip time is incorrect');
 }
コード例 #4
0
 function isNewToday($ip, $reg_time)
 {
     $ip = Ip::encode($ip);
     if (($record = $this->_getStatIpRecord($ip)) === false) {
         $this->_insertStatIpRecord($reg_time, $ip);
         return true;
     }
     $ip_date = new Date();
     $ip_date->setByStamp($record['time']);
     $reg_date = new Date();
     $reg_date->setByStamp($reg_time);
     if ($ip_date->dateToDays() < $reg_date->dateToDays()) {
         $this->_updateStatIpRecord($reg_time, $ip);
         return true;
     } elseif ($ip_date->dateToDays() > $reg_date->dateToDays()) {
         //this shouldn't happen normally...
         return false;
     }
     return false;
 }
コード例 #5
0
  function encodeIpRange($ip_begin, $ip_end)
  {
    $ip_regex = '/^([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/';

    if( ! preg_match($ip_regex, $ip_begin, $ip_begin_range_explode) ||
        ! preg_match($ip_regex, $ip_end, $ip_end_range_explode))
        return array();

    $ip_list = array();

    $ip_1_counter = $ip_begin_range_explode[1];
    $ip_1_end = $ip_end_range_explode[1];

    while ( $ip_1_counter <= $ip_1_end )
    {
      $ip_2_counter = ( $ip_1_counter == $ip_begin_range_explode[1] ) ? $ip_begin_range_explode[2] : 0;
      $ip_2_end = ( $ip_1_counter < $ip_1_end ) ? 254 : $ip_end_range_explode[2];

      if ( $ip_2_counter == 0 &&  $ip_2_end == 254 )
      {
        $ip_2_counter = 255;
        $ip_2_fragment = 255;

        $ip_list[] = Ip :: encode("{$ip_1_counter}.255.255.255");
      }

      while ( $ip_2_counter <= $ip_2_end )
      {
        $ip_3_counter = ( $ip_2_counter == $ip_begin_range_explode[2] &&  $ip_1_counter == $ip_begin_range_explode[1] ) ? $ip_begin_range_explode[3] : 0;
        $ip_3_end = ( $ip_2_counter < $ip_2_end ||  $ip_1_counter < $ip_1_end ) ? 254 : $ip_end_range_explode[3];

        if ( $ip_3_counter == 0 &&  $ip_3_end == 254 )
        {
          $ip_3_counter = 255;
          $ip_3_fragment = 255;

          $ip_list[] = Ip :: encode("{$ip_1_counter}.{$ip_2_counter}.255.255");
        }

        while ( $ip_3_counter <= $ip_3_end )
        {
          $ip_4_counter = ( $ip_3_counter == $ip_begin_range_explode[3] &&  $ip_2_counter == $ip_begin_range_explode[2] &&  $ip_1_counter == $ip_begin_range_explode[1] ) ? $ip_begin_range_explode[4] : 0;
          $ip_4_end = ( $ip_3_counter < $ip_3_end ||  $ip_2_counter < $ip_2_end ) ? 254 : $ip_end_range_explode[4];

          if ( $ip_4_counter == 0 &&  $ip_4_end == 254 )
          {
            $ip_4_counter = 255;
            $ip_4_fragment = 255;

            $ip_list[] = Ip :: encode("{$ip_1_counter}.{$ip_2_counter}.{$ip_3_counter}.255");
          }

          while ( $ip_4_counter <= $ip_4_end )
          {
            $ip_list[] = Ip :: encode("{$ip_1_counter}.{$ip_2_counter}.{$ip_3_counter}.{$ip_4_counter}");
            $ip_4_counter++;
          }
          $ip_3_counter++;
        }
        $ip_2_counter++;
      }
      $ip_1_counter++;
    }

    return $ip_list;
  }