php warnings
[Pman.MTrack] / Diff.php
1 <?php
2 class Pman_MTrack_Diff extends Pman {
3     
4     function getAuth()
5     {
6         die("nothing here yet");
7     }
8    
9    
10     static function toHTML($input)
11     {
12          
13         $nlines = 0;
14
15         if (is_resource($input)) {
16             $lines = array();
17             while (($line = fgets($input)) !== false) {
18               $lines[] = rtrim($line, "\r\n");
19             }
20             $input = $lines;
21         }
22         
23         // abase???
24         if (is_string($input)) {
25             $abase = md5($input);
26             $input = preg_split("/\r?\n/", $input);
27         } else {
28             $abase = md5(join("\n", $input));
29         }
30         
31         $ret = array();
32            
33         while (true) {
34              
35             
36             if (!count($input)) {
37                 break;
38             }
39             
40             $line = array_shift($input);
41             $nlines++;
42             
43             if (!strncmp($line, '@@ ', 3)) {
44                 /* done with preamble */
45                 break;
46             }
47             $ret[] = (object)array(
48                 
49                 'line' => $line,
50                 'meta' => true,
51                 'cls' =>'meta'
52                 
53             );
54              
55         }
56         $class = 'meta';
57           
58         $lines = array(0, 0);
59         $first = false;
60         
61         $in_meta = false;
62         
63         while (true) {
64             $class = 'unmod';
65             
66             if (preg_match("/^@@\s+-(\pN+)(?:,\pN+)?\s+\+(\pN+)(?:,\pN+)?\s*@@/",
67                   $line, $M)) {
68                 $lines[0] = (int)$M[1] - 1;
69                 $lines[1] = (int)$M[2] - 1;
70                 $class = 'meta';
71                 $first = true;
72                 $in_meta = false;
73             } else if (preg_match("/^diff /", $line)) {
74                 $class = 'meta';
75                 $in_meta=true;
76             
77             } elseif (strlen($line)) {
78                 if ($line[0] == '-') {
79                     $lines[0]++;
80                     $class = 'removed';
81                 } elseif ($line[0] == '+') {
82                     $lines[1]++;
83                     $class = 'added';
84                 } else {
85                     $lines[0]++;
86                     $lines[1]++;
87                 }
88             } else {
89                 $lines[0]++;
90                 $lines[1]++;
91             }
92             
93             
94             if ($in_meta) {
95                 $class = 'meta';
96             }
97             $cls = $class;
98             
99             if ($first) {
100                 $cls .= ' first';
101             } else
102             if ($class != 'meta' && $first) {
103                 $first = false;
104             }
105         
106
107             $anchor = $abase . '.' . $nlines;
108             $add = (object)array(
109                 
110                 'line' => $class == 'meta' ? $line : substr($line, 1),
111                 'meta' => $class == 'meta',
112                 'cls' => $cls,
113                 'anchor' => $class == 'meta' ? $anchor : false
114             );
115             
116             $add->$class = true;
117             
118             $ret[] = $add;
119            
120         
121             if (!count($input)) {
122                 break;
123             }
124             $line = array_shift($input);
125             $nlines++;
126         }
127           
128         if ($nlines == 0) {
129             return null;
130         }
131       
132         return $ret; 
133     }
134 }