Passed
Pull Request — master (#125)
by Chenyi
22:46
created
app/Http/Controllers/VirtualCrawler/SPOJ/SPOJ.php 3 patches
Indentation   +26 added lines, -26 removed lines patch added patch discarded remove patch
@@ -81,41 +81,41 @@  discard block
 block discarded – undo
81 81
         }else{
82 82
             $this->pro['title'] = trim(self::find('/<h2 id="problem-name".* - (.*)<\/h2>/sU',$res->body));
83 83
             $temp = $res->body;
84
-			$temp = explode('<tr><td>Time limit:</td><td>', $temp)[1];
85
-			$this->pro['time_limit']=trim(explode('s			</td></tr>', $temp)[0]); //as for html arrange
84
+            $temp = explode('<tr><td>Time limit:</td><td>', $temp)[1];
85
+            $this->pro['time_limit']=trim(explode('s			</td></tr>', $temp)[0]); //as for html arrange
86 86
             $temp = $res->body;
87 87
             $temp = explode('<tr><td>Memory limit:</td><td>', $temp)[1];
88
-			$this->pro['memory_limit']=trim(explode('MB</td></tr>' , $temp)[0]);
88
+            $this->pro['memory_limit']=trim(explode('MB</td></tr>' , $temp)[0]);
89 89
             $temp = $res->body;
90
-			$temp = explode('<tr><td>Languages:</td><td>', $temp)[1];
91
-			$this->pro['note'] = "Languages Limit:".explode('</td></tr>', $temp)[0];
90
+            $temp = explode('<tr><td>Languages:</td><td>', $temp)[1];
91
+            $this->pro['note'] = "Languages Limit:".explode('</td></tr>', $temp)[0];
92 92
 
93 93
             if(strpos($res->body, "<tr><td>Resource:</td><td>")!==false)
94
-			{
95
-				$temp = $res->body;
96
-				$temp = explode('<tr><td>Resource:</td><td>', $temp)[1];
97
-				$this->pro['source'] = strip_tags(explode('</td></tr>', $temp)[0]);
98
-			}else {
94
+            {
95
+                $temp = $res->body;
96
+                $temp = explode('<tr><td>Resource:</td><td>', $temp)[1];
97
+                $this->pro['source'] = strip_tags(explode('</td></tr>', $temp)[0]);
98
+            }else {
99 99
                 $this->pro['source'] = "SPOJ-".$pid;
100 100
             }
101 101
 
102 102
             if(strpos($res->body,"No tags")===false)
103
-			{
104
-				$temp = $res->body;
105
-				$temp = explode('<div id="problem-tags" class="col-lg-12 text-center">', $temp)[1];
106
-				$temp = explode('</div>', $temp)[0];
107
-				$cat = explode('<a href="/problems/tag/', $temp);
108
-				for($i = 1;$i < count($cat); $i++)
109
-				{
110
-					$temp = $cat[$i];
111
-					$temp = explode('">', $temp)[0];
112
-					array_push($cate,$temp);
113
-				}
114
-			}
103
+            {
104
+                $temp = $res->body;
105
+                $temp = explode('<div id="problem-tags" class="col-lg-12 text-center">', $temp)[1];
106
+                $temp = explode('</div>', $temp)[0];
107
+                $cat = explode('<a href="/problems/tag/', $temp);
108
+                for($i = 1;$i < count($cat); $i++)
109
+                {
110
+                    $temp = $cat[$i];
111
+                    $temp = explode('">', $temp)[0];
112
+                    array_push($cate,$temp);
113
+                }
114
+            }
115 115
 
116 116
             $temp = $res->body;
117
-			$temp = explode('<div id="problem-body">', $temp)[1];
118
-			$content = explode('<div class="text-center">', $temp)[0];
117
+            $temp = explode('<div id="problem-body">', $temp)[1];
118
+            $content = explode('<div class="text-center">', $temp)[0];
119 119
 
120 120
             $this->pro['description'] = $this->cacheImage(HtmlDomParser::str_get_html(explode('<h3>Input</h3>', $content)[0], true, true, DEFAULT_TARGET_CHARSET, false));
121 121
             $content = explode('<h3>Input</h3>', $content)[1];
@@ -141,11 +141,11 @@  discard block
 block discarded – undo
141 141
                 for($cnt = 1; $cnt < count($problemTable); $cnt++) {
142 142
                     $problemLink = $problemTable[$cnt];
143 143
                     $problemLink = explode('<a href="/problems/', $problemLink)[1];
144
-					$pid=explode('">', $problemLink)[0];
144
+                    $pid=explode('">', $problemLink)[0];
145 145
 
146 146
                     $problemLink = $problemTable[$cnt];
147 147
                     $problemLink = explode('See the best solutions.">', $problemLink)[1];
148
-					$solved_count=explode('</a></td>', $problemLink)[0];
148
+                    $solved_count=explode('</a></td>', $problemLink)[0];
149 149
 
150 150
                     $problemLink = $problemTable[$cnt];
151 151
                     $index = self::find('/<td align="center">([\s]*?)<\/td>/',$problemLink);
Please login to merge, or discard this patch.
Spacing   +64 added lines, -64 removed lines patch added patch discarded remove patch
@@ -23,9 +23,9 @@  discard block
 block discarded – undo
23 23
         set_time_limit(0); // Pandora's box, engage!
24 24
         if ($action=='judge_level') {
25 25
             $this->judge_level();
26
-        } else if($con=="all"){
26
+        } else if ($con=="all") {
27 27
             $this->getSpojProblem();
28
-        }else{
28
+        } else {
29 29
             //TODO
30 30
         }
31 31
     }
@@ -71,90 +71,90 @@  discard block
 block discarded – undo
71 71
     }
72 72
 
73 73
     public function getProblemDetail($pid) {
74
-        $cate = [];
74
+        $cate=[];
75 75
 
76
-        $url = "https://www.spoj.com/problems/".$pid;
77
-        $res = Requests::get($url);
78
-        if (strpos("<h1>Not Found</h1>",$res->body) !== false) {
76
+        $url="https://www.spoj.com/problems/".$pid;
77
+        $res=Requests::get($url);
78
+        if (strpos("<h1>Not Found</h1>", $res->body)!==false) {
79 79
             header('HTTP/1.1 404 Not Found');
80 80
             die();
81
-        }else{
82
-            $this->pro['title'] = trim(self::find('/<h2 id="problem-name".* - (.*)<\/h2>/sU',$res->body));
83
-            $temp = $res->body;
84
-			$temp = explode('<tr><td>Time limit:</td><td>', $temp)[1];
81
+        } else {
82
+            $this->pro['title']=trim(self::find('/<h2 id="problem-name".* - (.*)<\/h2>/sU', $res->body));
83
+            $temp=$res->body;
84
+			$temp=explode('<tr><td>Time limit:</td><td>', $temp)[1];
85 85
 			$this->pro['time_limit']=trim(explode('s			</td></tr>', $temp)[0]); //as for html arrange
86
-            $temp = $res->body;
87
-            $temp = explode('<tr><td>Memory limit:</td><td>', $temp)[1];
88
-			$this->pro['memory_limit']=trim(explode('MB</td></tr>' , $temp)[0]);
89
-            $temp = $res->body;
90
-			$temp = explode('<tr><td>Languages:</td><td>', $temp)[1];
91
-			$this->pro['note'] = "Languages Limit:".explode('</td></tr>', $temp)[0];
92
-
93
-            if(strpos($res->body, "<tr><td>Resource:</td><td>")!==false)
86
+            $temp=$res->body;
87
+            $temp=explode('<tr><td>Memory limit:</td><td>', $temp)[1];
88
+			$this->pro['memory_limit']=trim(explode('MB</td></tr>', $temp)[0]);
89
+            $temp=$res->body;
90
+			$temp=explode('<tr><td>Languages:</td><td>', $temp)[1];
91
+			$this->pro['note']="Languages Limit:".explode('</td></tr>', $temp)[0];
92
+
93
+            if (strpos($res->body, "<tr><td>Resource:</td><td>")!==false)
94 94
 			{
95
-				$temp = $res->body;
96
-				$temp = explode('<tr><td>Resource:</td><td>', $temp)[1];
97
-				$this->pro['source'] = strip_tags(explode('</td></tr>', $temp)[0]);
98
-			}else {
99
-                $this->pro['source'] = "SPOJ-".$pid;
95
+				$temp=$res->body;
96
+				$temp=explode('<tr><td>Resource:</td><td>', $temp)[1];
97
+				$this->pro['source']=strip_tags(explode('</td></tr>', $temp)[0]);
98
+			} else {
99
+                $this->pro['source']="SPOJ-".$pid;
100 100
             }
101 101
 
102
-            if(strpos($res->body,"No tags")===false)
102
+            if (strpos($res->body, "No tags")===false)
103 103
 			{
104
-				$temp = $res->body;
105
-				$temp = explode('<div id="problem-tags" class="col-lg-12 text-center">', $temp)[1];
106
-				$temp = explode('</div>', $temp)[0];
107
-				$cat = explode('<a href="/problems/tag/', $temp);
108
-				for($i = 1;$i < count($cat); $i++)
104
+				$temp=$res->body;
105
+				$temp=explode('<div id="problem-tags" class="col-lg-12 text-center">', $temp)[1];
106
+				$temp=explode('</div>', $temp)[0];
107
+				$cat=explode('<a href="/problems/tag/', $temp);
108
+				for ($i=1; $i<count($cat); $i++)
109 109
 				{
110
-					$temp = $cat[$i];
111
-					$temp = explode('">', $temp)[0];
112
-					array_push($cate,$temp);
110
+					$temp=$cat[$i];
111
+					$temp=explode('">', $temp)[0];
112
+					array_push($cate, $temp);
113 113
 				}
114 114
 			}
115 115
 
116
-            $temp = $res->body;
117
-			$temp = explode('<div id="problem-body">', $temp)[1];
118
-			$content = explode('<div class="text-center">', $temp)[0];
116
+            $temp=$res->body;
117
+			$temp=explode('<div id="problem-body">', $temp)[1];
118
+			$content=explode('<div class="text-center">', $temp)[0];
119 119
 
120
-            $this->pro['description'] = $this->cacheImage(HtmlDomParser::str_get_html(explode('<h3>Input</h3>', $content)[0], true, true, DEFAULT_TARGET_CHARSET, false));
121
-            $content = explode('<h3>Input</h3>', $content)[1];
122
-            $this->pro['input'] = explode('<h3>Output</h3>', $content)[0];
123
-            $content = explode('<h3>Output</h3>', $content)[1];
124
-            $tgis->pro['output'] = explode('<h3>Example</h3>', $content)[0];
125
-            $content = explode('<h3>Example</h3>', $content)[1];
120
+            $this->pro['description']=$this->cacheImage(HtmlDomParser::str_get_html(explode('<h3>Input</h3>', $content)[0], true, true, DEFAULT_TARGET_CHARSET, false));
121
+            $content=explode('<h3>Input</h3>', $content)[1];
122
+            $this->pro['input']=explode('<h3>Output</h3>', $content)[0];
123
+            $content=explode('<h3>Output</h3>', $content)[1];
124
+            $tgis->pro['output']=explode('<h3>Example</h3>', $content)[0];
125
+            $content=explode('<h3>Example</h3>', $content)[1];
126 126
 
127 127
             //TODO: Get compiler of each problem. 
128 128
         }
129 129
     }
130 130
 
131 131
     public function getSpojProblem() {
132
-        $types = ['classical','challenge','partial','tutorial','riddle','basics'];
133
-
134
-        foreach($types as $type) {
135
-            $iterator = 0;
136
-            $endPos = false;
137
-            while($endPos == false) {
138
-                $url = "https://www.spoj.com/problems/".$type."/sort=0,start=".$iterator*50;
139
-                $res = Requests::get($url);
140
-                $problemTable = explode('<td align="left">', $res->body);
141
-                for($cnt = 1; $cnt < count($problemTable); $cnt++) {
142
-                    $problemLink = $problemTable[$cnt];
143
-                    $problemLink = explode('<a href="/problems/', $problemLink)[1];
132
+        $types=['classical', 'challenge', 'partial', 'tutorial', 'riddle', 'basics'];
133
+
134
+        foreach ($types as $type) {
135
+            $iterator=0;
136
+            $endPos=false;
137
+            while ($endPos==false) {
138
+                $url="https://www.spoj.com/problems/".$type."/sort=0,start=".$iterator * 50;
139
+                $res=Requests::get($url);
140
+                $problemTable=explode('<td align="left">', $res->body);
141
+                for ($cnt=1; $cnt<count($problemTable); $cnt++) {
142
+                    $problemLink=$problemTable[$cnt];
143
+                    $problemLink=explode('<a href="/problems/', $problemLink)[1];
144 144
 					$pid=explode('">', $problemLink)[0];
145 145
 
146
-                    $problemLink = $problemTable[$cnt];
147
-                    $problemLink = explode('See the best solutions.">', $problemLink)[1];
146
+                    $problemLink=$problemTable[$cnt];
147
+                    $problemLink=explode('See the best solutions.">', $problemLink)[1];
148 148
 					$solved_count=explode('</a></td>', $problemLink)[0];
149 149
 
150
-                    $problemLink = $problemTable[$cnt];
151
-                    $index = self::find('/<td align="center">([\s]*?)<\/td>/',$problemLink);
150
+                    $problemLink=$problemTable[$cnt];
151
+                    $index=self::find('/<td align="center">([\s]*?)<\/td>/', $problemLink);
152 152
 
153
-                    $this->pro['pcode'] = "SPOJ-".$pid;
154
-                    $this->pro['OJ'] = 10;
155
-                    $this->pro['contest_id'] = null;
156
-                    $this->pro['index_id'] = $index;
157
-                    $this->pro['origin'] = "https://www.spoj.com/problems/".$pid;
153
+                    $this->pro['pcode']="SPOJ-".$pid;
154
+                    $this->pro['OJ']=10;
155
+                    $this->pro['contest_id']=null;
156
+                    $this->pro['index_id']=$index;
157
+                    $this->pro['origin']="https://www.spoj.com/problems/".$pid;
158 158
                     $this->pro['input_type']='standard input';
159 159
                     $this->pro['output_type']='standard output';
160 160
                     $this->getProblemDetail($pid);
@@ -164,11 +164,11 @@  discard block
 block discarded – undo
164 164
                     if ($problem) {
165 165
                         $problemModel->clearTags($problem);
166 166
                         $new_pid=$this->update_problem($this->oid);
167
-                    }else {
167
+                    } else {
168 168
                         $new_pid=$this->insert_problem($this->oid);
169 169
                     }
170 170
                 }
171
-                if(count($table) < 50) $endPos = true;
171
+                if (count($table)<50) $endPos=true;
172 172
                 $iterator++;
173 173
             }
174 174
         }
Please login to merge, or discard this patch.
Braces   +7 added lines, -5 removed lines patch added patch discarded remove patch
@@ -25,7 +25,7 @@  discard block
 block discarded – undo
25 25
             $this->judge_level();
26 26
         } else if($con=="all"){
27 27
             $this->getSpojProblem();
28
-        }else{
28
+        } else{
29 29
             //TODO
30 30
         }
31 31
     }
@@ -78,7 +78,7 @@  discard block
 block discarded – undo
78 78
         if (strpos("<h1>Not Found</h1>",$res->body) !== false) {
79 79
             header('HTTP/1.1 404 Not Found');
80 80
             die();
81
-        }else{
81
+        } else{
82 82
             $this->pro['title'] = trim(self::find('/<h2 id="problem-name".* - (.*)<\/h2>/sU',$res->body));
83 83
             $temp = $res->body;
84 84
 			$temp = explode('<tr><td>Time limit:</td><td>', $temp)[1];
@@ -95,7 +95,7 @@  discard block
 block discarded – undo
95 95
 				$temp = $res->body;
96 96
 				$temp = explode('<tr><td>Resource:</td><td>', $temp)[1];
97 97
 				$this->pro['source'] = strip_tags(explode('</td></tr>', $temp)[0]);
98
-			}else {
98
+			} else {
99 99
                 $this->pro['source'] = "SPOJ-".$pid;
100 100
             }
101 101
 
@@ -164,11 +164,13 @@  discard block
 block discarded – undo
164 164
                     if ($problem) {
165 165
                         $problemModel->clearTags($problem);
166 166
                         $new_pid=$this->update_problem($this->oid);
167
-                    }else {
167
+                    } else {
168 168
                         $new_pid=$this->insert_problem($this->oid);
169 169
                     }
170 170
                 }
171
-                if(count($table) < 50) $endPos = true;
171
+                if(count($table) < 50) {
172
+                    $endPos = true;
173
+                }
172 174
                 $iterator++;
173 175
             }
174 176
         }
Please login to merge, or discard this patch.