~chromium-team/chromium-browser/trusty-beta

« back to all changes in this revision

Viewing changes to debian/tests/data/HTML5test/backend/libraries/tools.php

  • Committer: Olivier Tilloy
  • Date: 2017-10-23 16:46:53 UTC
  • mfrom: (1172.1.38 trusty-stable)
  • Revision ID: olivier.tilloy@canonical.com-20171023164653-zmpfzblxxnkj0jhj
Merge back changes from stable branch:
  * debian/control: bump Standards-Version to 4.1.1
  * debian/patches/set-rpath-on-chromium-executables.patch: updated
  * debian/tests/*:
    - removed stale autopkgtests
    - added new autopkgtests based on chromium's new headless mode
  * debian/source/include-binaries: updated to reflect new binary data in tests

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
 
 
3
 
 
4
        function time_ago ($tm, $rcs = 0) {
 
5
          $cur_tm = time();
 
6
          $dif = $cur_tm - $tm;
 
7
          $pds = array('second','minute','hour','day','week','month','year','decade');
 
8
          $lngh = array(1,60,3600,86400,604800,2630880,31570560,315705600);
 
9
 
 
10
          for ($v = count($lngh) - 1; ($v >= 0) && (($no = $dif / $lngh[$v]) <= 1); $v--);
 
11
            if ($v < 0)
 
12
              $v = 0;
 
13
          $_tm = $cur_tm - ($dif % $lngh[$v]);
 
14
 
 
15
          $no = ($rcs ? floor($no) : round($no)); // if last denomination, round
 
16
 
 
17
          if ($no != 1)
 
18
            $pds[$v] .= 's';
 
19
          $x = $no . ' ' . $pds[$v];
 
20
 
 
21
          if (($rcs > 0) && ($v >= 1))
 
22
            $x .= ' ' . $this->time_ago($_tm, $rcs - 1);
 
23
 
 
24
          return $x;
 
25
        }
 
26
 
 
27
 
 
28
        function get_ip_address() {
 
29
                $ip = $_SERVER['REMOTE_ADDR'];
 
30
 
 
31
                $headers = apache_request_headers();
 
32
                if (isset($headers['X-Forwarded-For'])) $ip = $headers['X-Forwarded-For'];
 
33
                if (isset($headers['Proxy-Client-IP'])) $ip = $headers['Proxy-Client-IP'];
 
34
                if (isset($headers['X-Client-IP'])) $ip = $headers['X-Client-IP'];
 
35
                if (isset($headers['Client-IP'])) $ip = $headers['Client-IP'];
 
36
 
 
37
                return $ip;
 
38
        }
 
39
 
 
40
        function opt_explode($echar, $str) {
 
41
                $newstrarr = [];
 
42
 
 
43
                if (strlen($echar) != 1 || strlen($str) == 0) {
 
44
                        return 0;
 
45
                }
 
46
 
 
47
                $str = trim($str);
 
48
 
 
49
                $idx=0;
 
50
                $arr=0;
 
51
 
 
52
                while($idx < strlen($str)) {
 
53
                        if($str[$idx] == '"') {
 
54
                                // quoted field
 
55
                                $idx++;
 
56
                                while ($idx < strlen($str)) {
 
57
                                        // look for ending quote
 
58
                                        if($str[$idx] == '"') {
 
59
                                                $idx++;
 
60
                                                $arr++;
 
61
                                                break;
 
62
                                        }
 
63
                                        $newstrarr[$arr] = $newstrarr[$arr] . $str[$idx];
 
64
                                        $idx++;
 
65
                                }
 
66
                        } elseif ($str[$idx] == $echar) {
 
67
                                // normal delimiter, advance element
 
68
                                $arr++;
 
69
                        } else {
 
70
                                // must be normal char, tack onto current element
 
71
                                if (isset($newstrarr[$arr])) {
 
72
                                        $newstrarr[$arr] = $newstrarr[$arr] . $str[$idx];
 
73
                                } else {
 
74
                                        $newstrarr[$arr] = $str[$idx];
 
75
                                }
 
76
                        }
 
77
                        $idx++;
 
78
                }
 
79
 
 
80
                return $newstrarr;
 
81
        }
 
 
b'\\ No newline at end of file'