@@ -18,12 +18,12 @@ |
||
| 18 | 18 | * |
| 19 | 19 | * @return Response |
| 20 | 20 | */ |
| 21 | - public function __construct($name,$action,$con,$cached = false) |
|
| 21 | + public function __construct($name, $action, $con, $cached=false) |
|
| 22 | 22 | { |
| 23 | - if($name=="CodeForces") new CodeForces($action,$con,$cached); |
|
| 24 | - if($name=="ContestHunter") new ContestHunter($action,$con,$cached); |
|
| 25 | - if($name=="POJ") new POJ($action,$con,$cached); |
|
| 26 | - if($name=="PTA") new PTA($action,$con,$cached); |
|
| 27 | - if($name=="Vijos") new Vijos($action,$con,$cached); |
|
| 23 | + if ($name=="CodeForces") new CodeForces($action, $con, $cached); |
|
| 24 | + if ($name=="ContestHunter") new ContestHunter($action, $con, $cached); |
|
| 25 | + if ($name=="POJ") new POJ($action, $con, $cached); |
|
| 26 | + if ($name=="PTA") new PTA($action, $con, $cached); |
|
| 27 | + if ($name=="Vijos") new Vijos($action, $con, $cached); |
|
| 28 | 28 | } |
| 29 | 29 | } |
@@ -20,10 +20,20 @@ |
||
| 20 | 20 | */ |
| 21 | 21 | public function __construct($name,$action,$con,$cached = false) |
| 22 | 22 | { |
| 23 | - if($name=="CodeForces") new CodeForces($action,$con,$cached); |
|
| 24 | - if($name=="ContestHunter") new ContestHunter($action,$con,$cached); |
|
| 25 | - if($name=="POJ") new POJ($action,$con,$cached); |
|
| 26 | - if($name=="PTA") new PTA($action,$con,$cached); |
|
| 27 | - if($name=="Vijos") new Vijos($action,$con,$cached); |
|
| 23 | + if($name=="CodeForces") { |
|
| 24 | + new CodeForces($action,$con,$cached); |
|
| 25 | + } |
|
| 26 | + if($name=="ContestHunter") { |
|
| 27 | + new ContestHunter($action,$con,$cached); |
|
| 28 | + } |
|
| 29 | + if($name=="POJ") { |
|
| 30 | + new POJ($action,$con,$cached); |
|
| 31 | + } |
|
| 32 | + if($name=="PTA") { |
|
| 33 | + new PTA($action,$con,$cached); |
|
| 34 | + } |
|
| 35 | + if($name=="Vijos") { |
|
| 36 | + new Vijos($action,$con,$cached); |
|
| 37 | + } |
|
| 28 | 38 | } |
| 29 | 39 | } |
@@ -5,7 +5,7 @@ discard block |
||
| 5 | 5 | use App\Http\Controllers\VirtualCrawler\CrawlerBase; |
| 6 | 6 | use App\Models\ProblemModel; |
| 7 | 7 | use KubAT\PhpSimple\HtmlDomParser; |
| 8 | -use Auth,Requests,Exception; |
|
| 8 | +use Auth, Requests, Exception; |
|
| 9 | 9 | |
| 10 | 10 | class Vijos extends CrawlerBase |
| 11 | 11 | { |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | * |
| 17 | 17 | * @return Response |
| 18 | 18 | */ |
| 19 | - public function __construct($action = 'crawl_problem', $con = 'all', $cached = false) |
|
| 19 | + public function __construct($action='crawl_problem', $con='all', $cached=false) |
|
| 20 | 20 | { |
| 21 | 21 | set_time_limit(0); // Pandora's box, engage! |
| 22 | 22 | if ($action=='judge_level') { |
@@ -33,38 +33,38 @@ discard block |
||
| 33 | 33 | |
| 34 | 34 | public function crawling($con) |
| 35 | 35 | { |
| 36 | - if ($con == 'all') { |
|
| 36 | + if ($con=='all') { |
|
| 37 | 37 | // TODO |
| 38 | 38 | return; |
| 39 | 39 | } |
| 40 | 40 | |
| 41 | 41 | try { |
| 42 | - $dom = HtmlDomParser::file_get_html('https://vijos.org/p/'.$con, false, null, 0, -1, true, true, DEFAULT_TARGET_CHARSET, false); |
|
| 42 | + $dom=HtmlDomParser::file_get_html('https://vijos.org/p/'.$con, false, null, 0, -1, true, true, DEFAULT_TARGET_CHARSET, false); |
|
| 43 | 43 | } |
| 44 | 44 | catch (Exception $e) { |
| 45 | - if (strpos($e->getMessage(), '404 Not Found') !== false) { |
|
| 45 | + if (strpos($e->getMessage(), '404 Not Found')!==false) { |
|
| 46 | 46 | header('HTTP/1.1 404 Not Found'); |
| 47 | 47 | die(); |
| 48 | 48 | } |
| 49 | - if (strpos($e->getMessage(), '403 Forbidden') !== false) { |
|
| 49 | + if (strpos($e->getMessage(), '403 Forbidden')!==false) { |
|
| 50 | 50 | header('HTTP/1.1 403 Forbidden'); |
| 51 | 51 | die(); |
| 52 | 52 | } |
| 53 | 53 | throw $e; |
| 54 | 54 | } |
| 55 | 55 | |
| 56 | - $mainDiv = $dom->find(".section__body", 0); |
|
| 56 | + $mainDiv=$dom->find(".section__body", 0); |
|
| 57 | 57 | |
| 58 | - $eles = $mainDiv->children(); |
|
| 58 | + $eles=$mainDiv->children(); |
|
| 59 | 59 | array_push($eles, null); |
| 60 | - $this->pro['description'] = null; |
|
| 61 | - $this->pro['input'] = null; |
|
| 62 | - $this->pro['output'] = null; |
|
| 63 | - $this->pro['sample'] = []; |
|
| 64 | - $this->pro['note'] = null; |
|
| 65 | - $this->pro['sampleDesc'] = null; |
|
| 66 | - $this->pro['limit'] = null; |
|
| 67 | - $patterns = [ |
|
| 60 | + $this->pro['description']=null; |
|
| 61 | + $this->pro['input']=null; |
|
| 62 | + $this->pro['output']=null; |
|
| 63 | + $this->pro['sample']=[]; |
|
| 64 | + $this->pro['note']=null; |
|
| 65 | + $this->pro['sampleDesc']=null; |
|
| 66 | + $this->pro['limit']=null; |
|
| 67 | + $patterns=[ |
|
| 68 | 68 | 'description' => '<h1>描述</h1>', |
| 69 | 69 | '_format' => '<h1>格式</h1>', |
| 70 | 70 | 'input' => '<h2>输入格式</h2>', |
@@ -77,77 +77,77 @@ discard block |
||
| 77 | 77 | 'sampleDesc' => '/<h1>样例(说明|解释)<\/h1>|<h2>样例说明1<\/h2>/', // P2036 has <h2>样例说明1</h2> |
| 78 | 78 | 'source' => '<h1>来源</h1>', |
| 79 | 79 | ]; |
| 80 | - $lastPart = ''; |
|
| 81 | - $content = ''; |
|
| 82 | - $cursample = []; |
|
| 80 | + $lastPart=''; |
|
| 81 | + $content=''; |
|
| 82 | + $cursample=[]; |
|
| 83 | 83 | foreach ($eles as $ele) { |
| 84 | - $html = $ele ? $ele->outertext : null; |
|
| 85 | - $match = !$ele; |
|
| 84 | + $html=$ele ? $ele->outertext : null; |
|
| 85 | + $match=!$ele; |
|
| 86 | 86 | if (!$match) { |
| 87 | 87 | foreach ($patterns as $key=>$value) { |
| 88 | - if ($value[0] != '/' && $html == $value || $value[0] == '/' && preg_match($value, $html)) { |
|
| 89 | - $match = $key; |
|
| 88 | + if ($value[0]!='/' && $html==$value || $value[0]=='/' && preg_match($value, $html)) { |
|
| 89 | + $match=$key; |
|
| 90 | 90 | break; |
| 91 | 91 | } |
| 92 | 92 | } |
| 93 | 93 | } |
| 94 | 94 | if (!$lastPart) { |
| 95 | - if ($match) $lastPart = $match; |
|
| 95 | + if ($match) $lastPart=$match; |
|
| 96 | 96 | continue; |
| 97 | 97 | } |
| 98 | 98 | if ($match) { |
| 99 | - if ($lastPart[0] != '_') { |
|
| 100 | - $this->pro[$lastPart] = $content; |
|
| 101 | - $content = ''; |
|
| 102 | - } else if ($lastPart == '__sampleOutput') { // Assume output always follows by input |
|
| 99 | + if ($lastPart[0]!='_') { |
|
| 100 | + $this->pro[$lastPart]=$content; |
|
| 101 | + $content=''; |
|
| 102 | + } else if ($lastPart=='__sampleOutput') { // Assume output always follows by input |
|
| 103 | 103 | array_push($this->pro['sample'], $cursample); |
| 104 | - $cursample = []; |
|
| 104 | + $cursample=[]; |
|
| 105 | 105 | } |
| 106 | - $lastPart = $match; |
|
| 106 | + $lastPart=$match; |
|
| 107 | 107 | } else { |
| 108 | - if ($lastPart[1] != '_') { |
|
| 109 | - if ($lastPart != 'source') $content .= $html; |
|
| 110 | - else $content .= $ele->innertext; |
|
| 108 | + if ($lastPart[1]!='_') { |
|
| 109 | + if ($lastPart!='source') $content.=$html; |
|
| 110 | + else $content.=$ele->innertext; |
|
| 111 | 111 | } else { // Code |
| 112 | - $code = trim($ele->find('code', 0)->innertext); |
|
| 113 | - if ($lastPart == '__sampleInput') { if (isset($cursample['sampleInput'])) die($con); } |
|
| 112 | + $code=trim($ele->find('code', 0)->innertext); |
|
| 113 | + if ($lastPart=='__sampleInput') { if (isset($cursample['sampleInput'])) die($con); } |
|
| 114 | 114 | else { if (isset($cursample['sampleOutput'])) die($con); } |
| 115 | - if (count($ele->children()) != 1) die($con); |
|
| 116 | - if ($lastPart == '__sampleInput') $cursample['sample_input'] = $code; |
|
| 117 | - else $cursample['sample_output'] = $code; |
|
| 115 | + if (count($ele->children())!=1) die($con); |
|
| 116 | + if ($lastPart=='__sampleInput') $cursample['sample_input']=$code; |
|
| 117 | + else $cursample['sample_output']=$code; |
|
| 118 | 118 | } |
| 119 | 119 | } |
| 120 | 120 | if (!$ele) break; |
| 121 | 121 | } |
| 122 | 122 | |
| 123 | - $this->pro['time_limit'] = 1000; |
|
| 124 | - $this->pro['memory_limit'] = 262144; |
|
| 123 | + $this->pro['time_limit']=1000; |
|
| 124 | + $this->pro['memory_limit']=262144; |
|
| 125 | 125 | if ($this->pro['sampleDesc']) { |
| 126 | - $this->pro['note'] = '<h3>样例说明</h3>'.$this->pro['sampleDesc'].$this->pro['note']; |
|
| 126 | + $this->pro['note']='<h3>样例说明</h3>'.$this->pro['sampleDesc'].$this->pro['note']; |
|
| 127 | 127 | } |
| 128 | 128 | if ($this->pro['limit']) { |
| 129 | - $this->pro['note'] = $this->pro['limit'].$this->pro['note']; |
|
| 130 | - $this->pro['time_limit'] = 0; |
|
| 131 | - $this->pro['memory_limit'] = 0; |
|
| 129 | + $this->pro['note']=$this->pro['limit'].$this->pro['note']; |
|
| 130 | + $this->pro['time_limit']=0; |
|
| 131 | + $this->pro['memory_limit']=0; |
|
| 132 | 132 | } |
| 133 | 133 | |
| 134 | - $this->pro['pcode'] = 'VIJ'.$con; |
|
| 135 | - $this->pro['OJ'] = $this->oid; |
|
| 136 | - $this->pro['contest_id'] = null; |
|
| 137 | - $this->pro['index_id'] = $con; |
|
| 138 | - $this->pro['origin'] = 'https://vijos.org/p/'.$con; |
|
| 139 | - $this->pro['title'] = $dom->find('.section__header', 0)->find('h1', 0)->innertext; |
|
| 140 | - $this->pro['input_type'] = 'standard input'; |
|
| 141 | - $this->pro['output_type'] = 'standard output'; |
|
| 134 | + $this->pro['pcode']='VIJ'.$con; |
|
| 135 | + $this->pro['OJ']=$this->oid; |
|
| 136 | + $this->pro['contest_id']=null; |
|
| 137 | + $this->pro['index_id']=$con; |
|
| 138 | + $this->pro['origin']='https://vijos.org/p/'.$con; |
|
| 139 | + $this->pro['title']=$dom->find('.section__header', 0)->find('h1', 0)->innertext; |
|
| 140 | + $this->pro['input_type']='standard input'; |
|
| 141 | + $this->pro['output_type']='standard output'; |
|
| 142 | 142 | |
| 143 | - $this->pro['markdown'] = 0; |
|
| 144 | - $this->pro['tot_score'] = 100; |
|
| 145 | - $this->pro["partial"] = 1; |
|
| 146 | - $this->pro['source'] = 'Vijos'; // Force Override |
|
| 143 | + $this->pro['markdown']=0; |
|
| 144 | + $this->pro['tot_score']=100; |
|
| 145 | + $this->pro["partial"]=1; |
|
| 146 | + $this->pro['source']='Vijos'; // Force Override |
|
| 147 | 147 | |
| 148 | - $info = $dom->find(".horizontal", 0); |
|
| 148 | + $info=$dom->find(".horizontal", 0); |
|
| 149 | 149 | preg_match('/<dt>已通过<\/dt>[\s\S]*<dd>(\d+)<\/dd>/', $info->innertext, $match); |
| 150 | - $this->pro['solved_count'] = $match[1]; |
|
| 150 | + $this->pro['solved_count']=$match[1]; |
|
| 151 | 151 | |
| 152 | 152 | $problemModel=new ProblemModel(); |
| 153 | 153 | $problem=$problemModel->pid($this->pro['pcode']); |
@@ -159,7 +159,7 @@ discard block |
||
| 159 | 159 | $new_pid=$this->insert_problem($this->oid); |
| 160 | 160 | } |
| 161 | 161 | |
| 162 | - $tags = $info->find('.hasjs--hide', 0); |
|
| 162 | + $tags=$info->find('.hasjs--hide', 0); |
|
| 163 | 163 | if ($tags) { |
| 164 | 164 | foreach ($tags->find('a') as $tag) { |
| 165 | 165 | $problemModel->addTags($new_pid, $tag->innertext); |
@@ -40,8 +40,7 @@ discard block |
||
| 40 | 40 | |
| 41 | 41 | try { |
| 42 | 42 | $dom = HtmlDomParser::file_get_html('https://vijos.org/p/'.$con, false, null, 0, -1, true, true, DEFAULT_TARGET_CHARSET, false); |
| 43 | - } |
|
| 44 | - catch (Exception $e) { |
|
| 43 | + } catch (Exception $e) { |
|
| 45 | 44 | if (strpos($e->getMessage(), '404 Not Found') !== false) { |
| 46 | 45 | header('HTTP/1.1 404 Not Found'); |
| 47 | 46 | die(); |
@@ -92,7 +91,9 @@ discard block |
||
| 92 | 91 | } |
| 93 | 92 | } |
| 94 | 93 | if (!$lastPart) { |
| 95 | - if ($match) $lastPart = $match; |
|
| 94 | + if ($match) { |
|
| 95 | + $lastPart = $match; |
|
| 96 | + } |
|
| 96 | 97 | continue; |
| 97 | 98 | } |
| 98 | 99 | if ($match) { |
@@ -106,18 +107,33 @@ discard block |
||
| 106 | 107 | $lastPart = $match; |
| 107 | 108 | } else { |
| 108 | 109 | if ($lastPart[1] != '_') { |
| 109 | - if ($lastPart != 'source') $content .= $html; |
|
| 110 | - else $content .= $ele->innertext; |
|
| 110 | + if ($lastPart != 'source') { |
|
| 111 | + $content .= $html; |
|
| 112 | + } else { |
|
| 113 | + $content .= $ele->innertext; |
|
| 114 | + } |
|
| 111 | 115 | } else { // Code |
| 112 | 116 | $code = trim($ele->find('code', 0)->innertext); |
| 113 | - if ($lastPart == '__sampleInput') { if (isset($cursample['sampleInput'])) die($con); } |
|
| 114 | - else { if (isset($cursample['sampleOutput'])) die($con); } |
|
| 115 | - if (count($ele->children()) != 1) die($con); |
|
| 116 | - if ($lastPart == '__sampleInput') $cursample['sample_input'] = $code; |
|
| 117 | - else $cursample['sample_output'] = $code; |
|
| 117 | + if ($lastPart == '__sampleInput') { if (isset($cursample['sampleInput'])) { |
|
| 118 | + die($con); |
|
| 119 | + } |
|
| 120 | + } else { if (isset($cursample['sampleOutput'])) { |
|
| 121 | + die($con); |
|
| 122 | + } |
|
| 123 | + } |
|
| 124 | + if (count($ele->children()) != 1) { |
|
| 125 | + die($con); |
|
| 126 | + } |
|
| 127 | + if ($lastPart == '__sampleInput') { |
|
| 128 | + $cursample['sample_input'] = $code; |
|
| 129 | + } else { |
|
| 130 | + $cursample['sample_output'] = $code; |
|
| 131 | + } |
|
| 118 | 132 | } |
| 119 | 133 | } |
| 120 | - if (!$ele) break; |
|
| 134 | + if (!$ele) { |
|
| 135 | + break; |
|
| 136 | + } |
|
| 121 | 137 | } |
| 122 | 138 | |
| 123 | 139 | $this->pro['time_limit'] = 1000; |