@@ -15,8 +15,8 @@ discard block |
||
| 15 | 15 | * |
| 16 | 16 | * @var array |
| 17 | 17 | */ |
| 18 | - protected $fillable = [ |
|
| 19 | - 'name', 'email', 'password','avatar' |
|
| 18 | + protected $fillable=[ |
|
| 19 | + 'name', 'email', 'password', 'avatar' |
|
| 20 | 20 | ]; |
| 21 | 21 | |
| 22 | 22 | /** |
@@ -24,7 +24,7 @@ discard block |
||
| 24 | 24 | * |
| 25 | 25 | * @var array |
| 26 | 26 | */ |
| 27 | - protected $hidden = [ |
|
| 27 | + protected $hidden=[ |
|
| 28 | 28 | 'password', 'remember_token', |
| 29 | 29 | ]; |
| 30 | 30 | } |
@@ -17,11 +17,11 @@ |
||
| 17 | 17 | * |
| 18 | 18 | * @return Response |
| 19 | 19 | */ |
| 20 | - public function __construct($name,$action,$con,$cached = false) |
|
| 20 | + public function __construct($name, $action, $con, $cached=false) |
|
| 21 | 21 | { |
| 22 | - if($name=="CodeForces") new CodeForces($action,$con,$cached); |
|
| 23 | - if($name=="ContestHunter") new ContestHunter($action,$con,$cached); |
|
| 24 | - if($name=="POJ") new POJ($action,$con,$cached); |
|
| 25 | - if($name=="PTA") new PTA($action,$con,$cached); |
|
| 22 | + if ($name=="CodeForces") new CodeForces($action, $con, $cached); |
|
| 23 | + if ($name=="ContestHunter") new ContestHunter($action, $con, $cached); |
|
| 24 | + if ($name=="POJ") new POJ($action, $con, $cached); |
|
| 25 | + if ($name=="PTA") new PTA($action, $con, $cached); |
|
| 26 | 26 | } |
| 27 | 27 | } |
@@ -19,9 +19,17 @@ |
||
| 19 | 19 | */ |
| 20 | 20 | public function __construct($name,$action,$con,$cached = false) |
| 21 | 21 | { |
| 22 | - if($name=="CodeForces") new CodeForces($action,$con,$cached); |
|
| 23 | - if($name=="ContestHunter") new ContestHunter($action,$con,$cached); |
|
| 24 | - if($name=="POJ") new POJ($action,$con,$cached); |
|
| 25 | - if($name=="PTA") new PTA($action,$con,$cached); |
|
| 22 | + if($name=="CodeForces") { |
|
| 23 | + new CodeForces($action,$con,$cached); |
|
| 24 | + } |
|
| 25 | + if($name=="ContestHunter") { |
|
| 26 | + new ContestHunter($action,$con,$cached); |
|
| 27 | + } |
|
| 28 | + if($name=="POJ") { |
|
| 29 | + new POJ($action,$con,$cached); |
|
| 30 | + } |
|
| 31 | + if($name=="PTA") { |
|
| 32 | + new PTA($action,$con,$cached); |
|
| 33 | + } |
|
| 26 | 34 | } |
| 27 | 35 | } |
@@ -9,7 +9,7 @@ discard block |
||
| 9 | 9 | class CrawlerBase |
| 10 | 10 | { |
| 11 | 11 | public $pro=[ |
| 12 | - 'file'=> 0 , |
|
| 12 | + 'file'=> 0, |
|
| 13 | 13 | 'pcode'=>'', |
| 14 | 14 | 'solved_count'=>'', |
| 15 | 15 | 'time_limit'=>'', |
@@ -44,7 +44,7 @@ discard block |
||
| 44 | 44 | |
| 45 | 45 | public static function cmp($a, $b) |
| 46 | 46 | { |
| 47 | - return ($a[1]>$b[1])?-1:1; |
|
| 47 | + return ($a[1]>$b[1]) ?-1 : 1; |
|
| 48 | 48 | } |
| 49 | 49 | |
| 50 | 50 | public function process_and_get_image($ori, $path, $baseurl, $space_deli, $cookie) |
@@ -60,10 +60,10 @@ discard block |
||
| 60 | 60 | $reg="/< *im[a]?g[^>]*src *= *[\"\\']?([^\"\\'>]*)[^>]*>/si"; |
| 61 | 61 | } |
| 62 | 62 | |
| 63 | - return preg_replace_callback($reg, function ($matches) use ($para) { |
|
| 63 | + return preg_replace_callback($reg, function($matches) use ($para) { |
|
| 64 | 64 | global $config; |
| 65 | 65 | $url=trim($matches[1]); |
| 66 | - if (stripos($url, "http://")===false&&stripos($url, "https://")===false) { |
|
| 66 | + if (stripos($url, "http://")===false && stripos($url, "https://")===false) { |
|
| 67 | 67 | if ($para["trans"]) { |
| 68 | 68 | $url=str_replace(" ", "%20", $url); |
| 69 | 69 | } |
@@ -72,7 +72,7 @@ discard block |
||
| 72 | 72 | $name=basename($url); |
| 73 | 73 | $name="images/".strtr($name, ":", "_"); |
| 74 | 74 | $result=str_replace(trim($matches[1]), "online_Judges/spoj/images/".strtr(basename($url), ":", "_"), $matches[0]); |
| 75 | - $ch = curl_init(); |
|
| 75 | + $ch=curl_init(); |
|
| 76 | 76 | curl_setopt($ch, CURLOPT_URL, $url); |
| 77 | 77 | curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); |
| 78 | 78 | curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); |
@@ -81,9 +81,9 @@ discard block |
||
| 81 | 81 | } |
| 82 | 82 | curl_setopt($ch, CURLOPT_HEADER, 0); |
| 83 | 83 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
| 84 | - $content = curl_exec($ch); |
|
| 84 | + $content=curl_exec($ch); |
|
| 85 | 85 | curl_close($ch); |
| 86 | - $fp = fopen($name, "wb"); |
|
| 86 | + $fp=fopen($name, "wb"); |
|
| 87 | 87 | fwrite($fp, $content); |
| 88 | 88 | fclose($fp); |
| 89 | 89 | return $result; |
@@ -101,13 +101,13 @@ discard block |
||
| 101 | 101 | |
| 102 | 102 | public function get_url($url) |
| 103 | 103 | { |
| 104 | - $ch = curl_init(); |
|
| 104 | + $ch=curl_init(); |
|
| 105 | 105 | curl_setopt($ch, CURLOPT_URL, $url); |
| 106 | 106 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
| 107 | 107 | curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); |
| 108 | 108 | curl_setopt($ch, CURLOPT_HEADER, 0); |
| 109 | 109 | curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); |
| 110 | - $content = curl_exec($ch); |
|
| 110 | + $content=curl_exec($ch); |
|
| 111 | 111 | curl_close($ch); |
| 112 | 112 | return $content; |
| 113 | 113 | } |
@@ -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 POJ 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') { |
@@ -39,8 +39,8 @@ discard block |
||
| 39 | 39 | |
| 40 | 40 | private function getDOM($html, $start, $end) |
| 41 | 41 | { |
| 42 | - if ($start === false || $end === false) throw new Exception("Missing keywords."); |
|
| 43 | - return $this->cacheImage(HtmlDomParser::str_get_html(substr($html, $start, $end - $start), true, true, DEFAULT_TARGET_CHARSET, false)); |
|
| 42 | + if ($start===false || $end===false) throw new Exception("Missing keywords."); |
|
| 43 | + return $this->cacheImage(HtmlDomParser::str_get_html(substr($html, $start, $end-$start), true, true, DEFAULT_TARGET_CHARSET, false)); |
|
| 44 | 44 | } |
| 45 | 45 | |
| 46 | 46 | private function getInnertext($html, $start, $end, $tag) |
@@ -51,96 +51,96 @@ discard block |
||
| 51 | 51 | private function cacheImage($dom) |
| 52 | 52 | { |
| 53 | 53 | foreach ($dom->find('img') as $ele) { |
| 54 | - if (strpos($ele->src, '://') !== false) { |
|
| 55 | - $url = $ele->src; |
|
| 56 | - } else if ($ele->src[0] == '/') { |
|
| 57 | - $url = 'http://poj.org'.$ele->src; |
|
| 54 | + if (strpos($ele->src, '://')!==false) { |
|
| 55 | + $url=$ele->src; |
|
| 56 | + } else if ($ele->src[0]=='/') { |
|
| 57 | + $url='http://poj.org'.$ele->src; |
|
| 58 | 58 | } else { |
| 59 | - $url = 'http://poj.org/'.$ele->src; |
|
| 59 | + $url='http://poj.org/'.$ele->src; |
|
| 60 | 60 | } |
| 61 | - $res = Requests::get($url, ['Referer' => 'http://poj.org']); |
|
| 62 | - $ext = ['image/jpeg'=>'.jpg', 'image/png'=>'.png', 'image/gif'=>'.gif', 'image/bmp'=>'.bmp']; |
|
| 63 | - if (isset($res->headers['content-type'])) $cext = $ext[$res->headers['content-type']]; |
|
| 61 | + $res=Requests::get($url, ['Referer' => 'http://poj.org']); |
|
| 62 | + $ext=['image/jpeg'=>'.jpg', 'image/png'=>'.png', 'image/gif'=>'.gif', 'image/bmp'=>'.bmp']; |
|
| 63 | + if (isset($res->headers['content-type'])) $cext=$ext[$res->headers['content-type']]; |
|
| 64 | 64 | else { |
| 65 | - $pos = strpos($ele->src, '.'); |
|
| 66 | - if ($pos === false) $cext = ''; |
|
| 67 | - else $cext = substr($ele->src, $pos); |
|
| 65 | + $pos=strpos($ele->src, '.'); |
|
| 66 | + if ($pos===false) $cext=''; |
|
| 67 | + else $cext=substr($ele->src, $pos); |
|
| 68 | 68 | } |
| 69 | - $fn = $this->con.'_'.($this->imgi++).$cext; |
|
| 70 | - $dir = base_path("public/external/poj/img"); |
|
| 69 | + $fn=$this->con.'_'.($this->imgi++).$cext; |
|
| 70 | + $dir=base_path("public/external/poj/img"); |
|
| 71 | 71 | if (!file_exists($dir)) { |
| 72 | 72 | mkdir($dir, 0755, true); |
| 73 | 73 | } |
| 74 | 74 | file_put_contents(base_path("public/external/poj/img/$fn"), $res->body); |
| 75 | - $ele->src = '/external/poj/img/'.$fn; |
|
| 75 | + $ele->src='/external/poj/img/'.$fn; |
|
| 76 | 76 | } |
| 77 | 77 | return $dom; |
| 78 | 78 | } |
| 79 | 79 | |
| 80 | 80 | public function ContestHunter($con) |
| 81 | 81 | { |
| 82 | - if ($con == 'all') { |
|
| 82 | + if ($con=='all') { |
|
| 83 | 83 | // TODO |
| 84 | 84 | return; |
| 85 | 85 | } |
| 86 | - $this->con = $con; |
|
| 87 | - $this->imgi = 1; |
|
| 86 | + $this->con=$con; |
|
| 87 | + $this->imgi=1; |
|
| 88 | 88 | $problemModel=new ProblemModel(); |
| 89 | - $res = Requests::get("http://poj.org/problem?id={$con}&lang=zh-CN&change=true"); // I have no idea what does `change` refers to |
|
| 90 | - if (strpos($res->body, 'Can not find problem') !== false) { |
|
| 89 | + $res=Requests::get("http://poj.org/problem?id={$con}&lang=zh-CN&change=true"); // I have no idea what does `change` refers to |
|
| 90 | + if (strpos($res->body, 'Can not find problem')!==false) { |
|
| 91 | 91 | header('HTTP/1.1 404 Not Found'); |
| 92 | 92 | die(); |
| 93 | 93 | } |
| 94 | - $this->pro['pcode'] = 'POJ'.$con; |
|
| 95 | - $this->pro['OJ'] = $this->oid; |
|
| 96 | - $this->pro['contest_id'] = null; |
|
| 97 | - $this->pro['index_id'] = $con; |
|
| 98 | - $this->pro['origin'] = "http://poj.org/problem?id={$con}&lang=zh-CN&change=true"; |
|
| 99 | - $this->pro['title'] = POJ::find('/<div class="ptt" lang=".*?">(.*?)<\/div>/', $res->body); |
|
| 100 | - $this->pro['time_limit'] = POJ::find('/Time Limit:.*?(\d+)MS/', $res->body); |
|
| 101 | - $this->pro['memory_limit'] = POJ::find('/Memory Limit:.*?(\d+)K/', $res->body); |
|
| 102 | - $this->pro['solved_count'] = POJ::find('/Accepted:.*?(\d+)/', $res->body); |
|
| 103 | - $this->pro['input_type'] = 'standard input'; |
|
| 104 | - $this->pro['output_type'] = 'standard output'; |
|
| 105 | - $descPattern = '<p class="pst">Description</p>'; |
|
| 106 | - $inputPattern = '<p class="pst">Input</p>'; |
|
| 107 | - $outputPattern = '<p class="pst">Output</p>'; |
|
| 108 | - $sampleInputPattern = '<p class="pst">Sample Input</p>'; |
|
| 109 | - $sampleOutputPattern = '<p class="pst">Sample Output</p>'; |
|
| 110 | - $notePattern = '<p class="pst">Hint</p>'; |
|
| 111 | - $sourcePattern = '<p class="pst">Source</p>'; |
|
| 112 | - $endPattern = '</td>'; |
|
| 94 | + $this->pro['pcode']='POJ'.$con; |
|
| 95 | + $this->pro['OJ']=$this->oid; |
|
| 96 | + $this->pro['contest_id']=null; |
|
| 97 | + $this->pro['index_id']=$con; |
|
| 98 | + $this->pro['origin']="http://poj.org/problem?id={$con}&lang=zh-CN&change=true"; |
|
| 99 | + $this->pro['title']=POJ::find('/<div class="ptt" lang=".*?">(.*?)<\/div>/', $res->body); |
|
| 100 | + $this->pro['time_limit']=POJ::find('/Time Limit:.*?(\d+)MS/', $res->body); |
|
| 101 | + $this->pro['memory_limit']=POJ::find('/Memory Limit:.*?(\d+)K/', $res->body); |
|
| 102 | + $this->pro['solved_count']=POJ::find('/Accepted:.*?(\d+)/', $res->body); |
|
| 103 | + $this->pro['input_type']='standard input'; |
|
| 104 | + $this->pro['output_type']='standard output'; |
|
| 105 | + $descPattern='<p class="pst">Description</p>'; |
|
| 106 | + $inputPattern='<p class="pst">Input</p>'; |
|
| 107 | + $outputPattern='<p class="pst">Output</p>'; |
|
| 108 | + $sampleInputPattern='<p class="pst">Sample Input</p>'; |
|
| 109 | + $sampleOutputPattern='<p class="pst">Sample Output</p>'; |
|
| 110 | + $notePattern='<p class="pst">Hint</p>'; |
|
| 111 | + $sourcePattern='<p class="pst">Source</p>'; |
|
| 112 | + $endPattern='</td>'; |
|
| 113 | 113 | |
| 114 | - $pos1 = strpos($res->body, $descPattern) + strlen($descPattern); |
|
| 115 | - $pos2 = strpos($res->body, $inputPattern, $pos1); |
|
| 116 | - $this->pro['description'] = trim($this->getInnertext($res->body, $pos1, $pos2, 'div')); |
|
| 117 | - $pos1 = $pos2 + strlen($inputPattern); |
|
| 118 | - $pos2 = strpos($res->body, $outputPattern, $pos1); |
|
| 119 | - $this->pro['input'] = trim($this->getInnertext($res->body, $pos1, $pos2, 'div')); |
|
| 120 | - $pos1 = $pos2 + strlen($outputPattern); |
|
| 121 | - $pos2 = strpos($res->body, $sampleInputPattern, $pos1); |
|
| 122 | - $this->pro['output'] = trim($this->getInnertext($res->body, $pos1, $pos2, 'div')); |
|
| 123 | - $pos1 = $pos2 + strlen($sampleInputPattern); |
|
| 124 | - $pos2 = strpos($res->body, $sampleOutputPattern, $pos1); |
|
| 125 | - $sampleInput = $this->getInnertext($res->body, $pos1, $pos2, 'pre'); |
|
| 126 | - $pos1 = $pos2 + strlen($sampleOutputPattern); |
|
| 127 | - $pos2 = strpos($res->body, $notePattern, $pos1); |
|
| 128 | - if ($hasNote = ($pos2 !== false)) { |
|
| 129 | - $sampleOutput = $this->getInnertext($res->body, $pos1, $pos2, 'pre'); |
|
| 130 | - $pos1 = $pos2 + strlen($notePattern); |
|
| 114 | + $pos1=strpos($res->body, $descPattern)+strlen($descPattern); |
|
| 115 | + $pos2=strpos($res->body, $inputPattern, $pos1); |
|
| 116 | + $this->pro['description']=trim($this->getInnertext($res->body, $pos1, $pos2, 'div')); |
|
| 117 | + $pos1=$pos2+strlen($inputPattern); |
|
| 118 | + $pos2=strpos($res->body, $outputPattern, $pos1); |
|
| 119 | + $this->pro['input']=trim($this->getInnertext($res->body, $pos1, $pos2, 'div')); |
|
| 120 | + $pos1=$pos2+strlen($outputPattern); |
|
| 121 | + $pos2=strpos($res->body, $sampleInputPattern, $pos1); |
|
| 122 | + $this->pro['output']=trim($this->getInnertext($res->body, $pos1, $pos2, 'div')); |
|
| 123 | + $pos1=$pos2+strlen($sampleInputPattern); |
|
| 124 | + $pos2=strpos($res->body, $sampleOutputPattern, $pos1); |
|
| 125 | + $sampleInput=$this->getInnertext($res->body, $pos1, $pos2, 'pre'); |
|
| 126 | + $pos1=$pos2+strlen($sampleOutputPattern); |
|
| 127 | + $pos2=strpos($res->body, $notePattern, $pos1); |
|
| 128 | + if ($hasNote=($pos2!==false)) { |
|
| 129 | + $sampleOutput=$this->getInnertext($res->body, $pos1, $pos2, 'pre'); |
|
| 130 | + $pos1=$pos2+strlen($notePattern); |
|
| 131 | 131 | } |
| 132 | - $pos2 = strpos($res->body, $sourcePattern, $pos1); |
|
| 133 | - $temp = $this->getDOM($res->body, $pos1, $pos2); |
|
| 132 | + $pos2=strpos($res->body, $sourcePattern, $pos1); |
|
| 133 | + $temp=$this->getDOM($res->body, $pos1, $pos2); |
|
| 134 | 134 | if ($hasNote) { |
| 135 | - $this->pro['note'] = trim($temp->find('div', 0)->innertext()); |
|
| 135 | + $this->pro['note']=trim($temp->find('div', 0)->innertext()); |
|
| 136 | 136 | } else { |
| 137 | - $sampleOutput = $temp->find('pre', 0)->innertext(); |
|
| 138 | - $this->pro['note'] = null; |
|
| 137 | + $sampleOutput=$temp->find('pre', 0)->innertext(); |
|
| 138 | + $this->pro['note']=null; |
|
| 139 | 139 | } |
| 140 | - $this->pro['sample'] = [['sample_input'=>$sampleInput, 'sample_output'=>$sampleOutput]]; |
|
| 141 | - $pos1 = $pos2 + strlen($sourcePattern); |
|
| 142 | - $pos2 = strpos($res->body, $endPattern, $pos1); |
|
| 143 | - $this->pro['source'] = trim($this->getDOM($res->body, $pos1, $pos2)->find('div', 0)->find('a', 0)->innertext()); |
|
| 140 | + $this->pro['sample']=[['sample_input'=>$sampleInput, 'sample_output'=>$sampleOutput]]; |
|
| 141 | + $pos1=$pos2+strlen($sourcePattern); |
|
| 142 | + $pos2=strpos($res->body, $endPattern, $pos1); |
|
| 143 | + $this->pro['source']=trim($this->getDOM($res->body, $pos1, $pos2)->find('div', 0)->find('a', 0)->innertext()); |
|
| 144 | 144 | |
| 145 | 145 | $problem=$problemModel->pid($this->pro['pcode']); |
| 146 | 146 | |
@@ -33,13 +33,17 @@ discard block |
||
| 33 | 33 | |
| 34 | 34 | private static function find($pattern, $subject) |
| 35 | 35 | { |
| 36 | - if (preg_match($pattern, $subject, $matches)) return $matches[1]; |
|
| 36 | + if (preg_match($pattern, $subject, $matches)) { |
|
| 37 | + return $matches[1]; |
|
| 38 | + } |
|
| 37 | 39 | return NULL; |
| 38 | 40 | } |
| 39 | 41 | |
| 40 | 42 | private function getDOM($html, $start, $end) |
| 41 | 43 | { |
| 42 | - if ($start === false || $end === false) throw new Exception("Missing keywords."); |
|
| 44 | + if ($start === false || $end === false) { |
|
| 45 | + throw new Exception("Missing keywords."); |
|
| 46 | + } |
|
| 43 | 47 | return $this->cacheImage(HtmlDomParser::str_get_html(substr($html, $start, $end - $start), true, true, DEFAULT_TARGET_CHARSET, false)); |
| 44 | 48 | } |
| 45 | 49 | |
@@ -60,11 +64,15 @@ discard block |
||
| 60 | 64 | } |
| 61 | 65 | $res = Requests::get($url, ['Referer' => 'http://poj.org']); |
| 62 | 66 | $ext = ['image/jpeg'=>'.jpg', 'image/png'=>'.png', 'image/gif'=>'.gif', 'image/bmp'=>'.bmp']; |
| 63 | - if (isset($res->headers['content-type'])) $cext = $ext[$res->headers['content-type']]; |
|
| 64 | - else { |
|
| 67 | + if (isset($res->headers['content-type'])) { |
|
| 68 | + $cext = $ext[$res->headers['content-type']]; |
|
| 69 | + } else { |
|
| 65 | 70 | $pos = strpos($ele->src, '.'); |
| 66 | - if ($pos === false) $cext = ''; |
|
| 67 | - else $cext = substr($ele->src, $pos); |
|
| 71 | + if ($pos === false) { |
|
| 72 | + $cext = ''; |
|
| 73 | + } else { |
|
| 74 | + $cext = substr($ele->src, $pos); |
|
| 75 | + } |
|
| 68 | 76 | } |
| 69 | 77 | $fn = $this->con.'_'.($this->imgi++).$cext; |
| 70 | 78 | $dir = base_path("public/external/poj/img"); |
@@ -15,13 +15,13 @@ discard block |
||
| 15 | 15 | * |
| 16 | 16 | * @return Response |
| 17 | 17 | */ |
| 18 | - public function __construct($action = 'crawl_problem', $con = 'all', $cached = false) |
|
| 18 | + public function __construct($action='crawl_problem', $con='all', $cached=false) |
|
| 19 | 19 | { |
| 20 | 20 | set_time_limit(0); // Pandora's box, engage! |
| 21 | 21 | if ($action=='judge_level') { |
| 22 | 22 | $this->judge_level(); |
| 23 | 23 | } else { |
| 24 | - $this->Codeforces($con,$cached); |
|
| 24 | + $this->Codeforces($con, $cached); |
|
| 25 | 25 | } |
| 26 | 26 | } |
| 27 | 27 | |
@@ -29,15 +29,15 @@ discard block |
||
| 29 | 29 | { |
| 30 | 30 | $problemModel=new ProblemModel(); |
| 31 | 31 | $arr=$problemModel->getSolvedCount($this->oid); |
| 32 | - usort($arr, ["CrawlerBase","cmp"]); |
|
| 33 | - $m = count($arr)/10; |
|
| 32 | + usort($arr, ["CrawlerBase", "cmp"]); |
|
| 33 | + $m=count($arr) / 10; |
|
| 34 | 34 | for ($i=1; $i<=count($arr); $i++) { |
| 35 | - $level =ceil($i/$m); |
|
| 35 | + $level=ceil($i / $m); |
|
| 36 | 36 | $problemModel->updateDifficulty($arr[$i-1][0], $level); |
| 37 | 37 | } |
| 38 | 38 | } |
| 39 | 39 | |
| 40 | - public function extractCodeForces($cid, $num, $url, $default_desc = "") |
|
| 40 | + public function extractCodeForces($cid, $num, $url, $default_desc="") |
|
| 41 | 41 | { |
| 42 | 42 | $pid=$cid.$num; |
| 43 | 43 | $content=$this->get_url($url); |
@@ -48,18 +48,18 @@ discard block |
||
| 48 | 48 | } else { |
| 49 | 49 | if (stripos($content_type, "text/html")!==false) { |
| 50 | 50 | $this->pro["file"]=0; |
| 51 | - $first_step = explode('<div class="input-file"><div class="property-title">input</div>', $content); |
|
| 52 | - $second_step = explode("</div>", $first_step[1]); |
|
| 53 | - $this->pro["input_type"] = $second_step[0]; |
|
| 54 | - $first_step = explode('<div class="output-file"><div class="property-title">output</div>', $content); |
|
| 55 | - $second_step = explode("</div>", $first_step[1]); |
|
| 56 | - $this->pro["output_type"]= $second_step[0]; |
|
| 51 | + $first_step=explode('<div class="input-file"><div class="property-title">input</div>', $content); |
|
| 52 | + $second_step=explode("</div>", $first_step[1]); |
|
| 53 | + $this->pro["input_type"]=$second_step[0]; |
|
| 54 | + $first_step=explode('<div class="output-file"><div class="property-title">output</div>', $content); |
|
| 55 | + $second_step=explode("</div>", $first_step[1]); |
|
| 56 | + $this->pro["output_type"]=$second_step[0]; |
|
| 57 | 57 | |
| 58 | 58 | if (preg_match("/time limit per test<\\/div>(.*) second/sU", $content, $matches)) { |
| 59 | - $this->pro["time_limit"]=intval(trim($matches[1]))*1000; |
|
| 59 | + $this->pro["time_limit"]=intval(trim($matches[1])) * 1000; |
|
| 60 | 60 | } |
| 61 | 61 | if (preg_match("/memory limit per test<\\/div>(.*) megabyte/sU", $content, $matches)) { |
| 62 | - $this->pro["memory_limit"]=intval(trim($matches[1]))*1024; |
|
| 62 | + $this->pro["memory_limit"]=intval(trim($matches[1])) * 1024; |
|
| 63 | 63 | } |
| 64 | 64 | if (preg_match("/output<\\/div>.*<div>(<p>.*)<\\/div>/sU", $content, $matches)) { |
| 65 | 65 | $this->pro["description"].=trim(($matches[1])); |
@@ -71,20 +71,20 @@ discard block |
||
| 71 | 71 | $this->pro["output"]=trim($matches[1]); |
| 72 | 72 | } |
| 73 | 73 | |
| 74 | - if (strpos($content, '<div class="sample-test">') !== false) { |
|
| 74 | + if (strpos($content, '<div class="sample-test">')!==false) { |
|
| 75 | 75 | $temp_sample=explode('<div class="sample-test">', $content)[1]; |
| 76 | - if (!(strpos($content, '<div class="note">') !== false)) { |
|
| 76 | + if (!(strpos($content, '<div class="note">')!==false)) { |
|
| 77 | 77 | $temp_sample=explode('<script type="text/javascript">', $temp_sample)[0]; |
| 78 | 78 | } else { |
| 79 | 79 | $temp_sample=explode('<div class="note">', $temp_sample)[0]; |
| 80 | 80 | } |
| 81 | 81 | |
| 82 | 82 | $sample_list=HtmlDomParser::str_get_html($temp_sample); |
| 83 | - $sample_pairs=intval(count($sample_list->find('pre'))/2); |
|
| 83 | + $sample_pairs=intval(count($sample_list->find('pre')) / 2); |
|
| 84 | 84 | $this->pro["sample"]=[]; |
| 85 | 85 | for ($i=0; $i<$sample_pairs; $i++) { |
| 86 | - $sample_input=$sample_list->find('pre')[$i*2]->innertext; |
|
| 87 | - $sample_output=$sample_list->find('pre')[$i*2+1]->innertext; |
|
| 86 | + $sample_input=$sample_list->find('pre')[$i * 2]->innertext; |
|
| 87 | + $sample_output=$sample_list->find('pre')[$i * 2+1]->innertext; |
|
| 88 | 88 | array_push($this->pro["sample"], [ |
| 89 | 89 | "sample_input"=>$sample_input, |
| 90 | 90 | "sample_output"=>$sample_output |
@@ -111,7 +111,7 @@ discard block |
||
| 111 | 111 | } elseif (stripos($content_type, "application/vnd.openxmlformats-officedocument.wordprocessingml.document")!==false) { |
| 112 | 112 | $ext="docx"; |
| 113 | 113 | } |
| 114 | - $dir = base_path("public/external/gym"); |
|
| 114 | + $dir=base_path("public/external/gym"); |
|
| 115 | 115 | if (!file_exists($dir)) { |
| 116 | 116 | mkdir($dir, 0755, true); |
| 117 | 117 | } |
@@ -130,7 +130,7 @@ discard block |
||
| 130 | 130 | } |
| 131 | 131 | |
| 132 | 132 | |
| 133 | - public function CodeForces($con,$cached) |
|
| 133 | + public function CodeForces($con, $cached) |
|
| 134 | 134 | { |
| 135 | 135 | $problemModel=new ProblemModel(); |
| 136 | 136 | $start=time(); |
@@ -144,14 +144,14 @@ discard block |
||
| 144 | 144 | $response=curl_exec($ch); |
| 145 | 145 | curl_close($ch); |
| 146 | 146 | // cache to folder |
| 147 | - $fp = fopen(__DIR__."/problemset.problems", "w"); |
|
| 147 | + $fp=fopen(__DIR__."/problemset.problems", "w"); |
|
| 148 | 148 | fwrite($fp, $response); |
| 149 | 149 | fclose($fp); |
| 150 | 150 | } |
| 151 | 151 | $result=json_decode($response, true); |
| 152 | 152 | if ($result["status"]=="OK") { |
| 153 | 153 | $now=time()-$start; |
| 154 | - $f = fopen(__DIR__."/codeforces_status.log", "w") or die("Unable to open file!"); |
|
| 154 | + $f=fopen(__DIR__."/codeforces_status.log", "w") or die("Unable to open file!"); |
|
| 155 | 155 | fwrite($f, "CodeForces API Success at {$now}".PHP_EOL); |
| 156 | 156 | for ($i=count($result['result']['problems'])-1; $i>=0; $i--) { |
| 157 | 157 | foreach ($this->pro as $x => $y) { |
@@ -164,7 +164,7 @@ discard block |
||
| 164 | 164 | } |
| 165 | 165 | } |
| 166 | 166 | |
| 167 | - $this->pro['origin'] = "http://codeforces.com/contest/{$result['result']['problems'][$i]['contestId']}/problem/{$result['result']['problems'][$i]['index']}"; |
|
| 167 | + $this->pro['origin']="http://codeforces.com/contest/{$result['result']['problems'][$i]['contestId']}/problem/{$result['result']['problems'][$i]['index']}"; |
|
| 168 | 168 | $this->pro['title']=str_replace('"', "'", $result['result']['problems'][$i]['name']); |
| 169 | 169 | $this->pro['solved_count']=$result['result']['problemStatistics'][$i]['solvedCount']; |
| 170 | 170 | $this->pro['pcode']="CF".$result['result']['problems'][$i]['contestId'].$result['result']['problems'][$i]['index']; |
@@ -6,7 +6,7 @@ discard block |
||
| 6 | 6 | use App\Models\ProblemModel; |
| 7 | 7 | use KubAT\PhpSimple\HtmlDomParser; |
| 8 | 8 | use Auth; |
| 9 | -use Requests,Exception; |
|
| 9 | +use Requests, Exception; |
|
| 10 | 10 | |
| 11 | 11 | class ContestHunter extends CrawlerBase |
| 12 | 12 | { |
@@ -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') { |
@@ -47,13 +47,13 @@ discard block |
||
| 47 | 47 | { |
| 48 | 48 | $problemModel=new ProblemModel(); |
| 49 | 49 | $start=time(); |
| 50 | - $f = fopen(__DIR__."/contesthunter_status.log", "w") or die("Unable to open file!"); |
|
| 50 | + $f=fopen(__DIR__."/contesthunter_status.log", "w") or die("Unable to open file!"); |
|
| 51 | 51 | try { |
| 52 | - $res = Requests::get("http://contest-hunter.org:83/contest?type=1"); |
|
| 52 | + $res=Requests::get("http://contest-hunter.org:83/contest?type=1"); |
|
| 53 | 53 | } |
| 54 | 54 | catch (Exception $e) { |
| 55 | 55 | try { // It seems that first query often fails |
| 56 | - $res = Requests::get("http://contest-hunter.org:83/contest?type=1"); |
|
| 56 | + $res=Requests::get("http://contest-hunter.org:83/contest?type=1"); |
|
| 57 | 57 | } |
| 58 | 58 | catch (Exception $e2) { |
| 59 | 59 | fwrite($f, "Loaded contest list failed.".PHP_EOL); |
@@ -64,122 +64,122 @@ discard block |
||
| 64 | 64 | preg_match_all('/<a href="\/contest\/([0-9A-Za-z$\-_.+!*\'\(\),%]*)"/', $res->body, $matches); |
| 65 | 65 | $now=time()-$start; |
| 66 | 66 | fwrite($f, "Loaded contest list at {$now}".PHP_EOL); |
| 67 | - $rcnames = array_reverse($matches[1]); |
|
| 67 | + $rcnames=array_reverse($matches[1]); |
|
| 68 | 68 | foreach ($rcnames as $rcname) { |
| 69 | 69 | $now=time()-$start; |
| 70 | - $cname = urldecode($rcname); |
|
| 71 | - $cid = substr($rcname, 0, 4); |
|
| 72 | - $tag = NULL; |
|
| 73 | - if (preg_match('/「(.*?)」/u', $cname, $match)) $tag = $match[1]; |
|
| 70 | + $cname=urldecode($rcname); |
|
| 71 | + $cid=substr($rcname, 0, 4); |
|
| 72 | + $tag=NULL; |
|
| 73 | + if (preg_match('/「(.*?)」/u', $cname, $match)) $tag=$match[1]; |
|
| 74 | 74 | try { |
| 75 | 75 | $now=time()-$start; |
| 76 | 76 | fwrite($f, "Start loading problem list of {$cid} at {$now}".PHP_EOL); |
| 77 | - $res = Requests::get("http://contest-hunter.org:83/contest/{$rcname}"); |
|
| 77 | + $res=Requests::get("http://contest-hunter.org:83/contest/{$rcname}"); |
|
| 78 | 78 | preg_match_all('/<a href="\/contest\/[0-9A-Za-z$\-_.+!*\'\(\),%]*\/([0-9A-Fa-f]{4}%20[0-9A-Za-z$\-_.+!*\'\(\),%]*)"/', $res->body, $matches); |
| 79 | - $rpnames = $matches[1]; |
|
| 79 | + $rpnames=$matches[1]; |
|
| 80 | 80 | foreach ($rpnames as $rpname) { |
| 81 | - $pname = urldecode($rpname); |
|
| 82 | - $pid = substr($rpname, 0, 4); |
|
| 81 | + $pname=urldecode($rpname); |
|
| 82 | + $pid=substr($rpname, 0, 4); |
|
| 83 | 83 | $now=time()-$start; |
| 84 | 84 | fwrite($f, "Start loading problem {$pid} at {$now}".PHP_EOL); |
| 85 | 85 | try { |
| 86 | - $res = Requests::get("http://contest-hunter.org:83/contest/{$rcname}/{$rpname}"); |
|
| 86 | + $res=Requests::get("http://contest-hunter.org:83/contest/{$rcname}/{$rpname}"); |
|
| 87 | 87 | |
| 88 | - $tests = ContestHunter::find('/<dt>测试点数<\/dt>\s*<dd>\s*(\d+)\s*<\/dd>/u', $res->body); |
|
| 89 | - $totalTimeLimit = ContestHunter::find('/<dt>总时限<\/dt>\s*<dd>\s*([\d.]+) s\s*<\/dd>/u', $res->body); |
|
| 90 | - if ($tests) $timeLimit = $totalTimeLimit * 1000 / $tests; |
|
| 91 | - $memoryLimit = ContestHunter::find('/<dt>总内存<\/dt>\s*<dd>\s*(\d+) MiB\s*<\/dd>/u', $res->body); |
|
| 92 | - if ($memoryLimit) $memoryLimit *= 1024; |
|
| 93 | - $passes = ContestHunter::find('/<dt>通过率<\/dt>\s*<dd>\s*([\d,]+)\/[\d,]+\s*<\/dd>/u', $res->body); |
|
| 94 | - $speTimeLimits = [ |
|
| 88 | + $tests=ContestHunter::find('/<dt>测试点数<\/dt>\s*<dd>\s*(\d+)\s*<\/dd>/u', $res->body); |
|
| 89 | + $totalTimeLimit=ContestHunter::find('/<dt>总时限<\/dt>\s*<dd>\s*([\d.]+) s\s*<\/dd>/u', $res->body); |
|
| 90 | + if ($tests) $timeLimit=$totalTimeLimit * 1000 / $tests; |
|
| 91 | + $memoryLimit=ContestHunter::find('/<dt>总内存<\/dt>\s*<dd>\s*(\d+) MiB\s*<\/dd>/u', $res->body); |
|
| 92 | + if ($memoryLimit) $memoryLimit*=1024; |
|
| 93 | + $passes=ContestHunter::find('/<dt>通过率<\/dt>\s*<dd>\s*([\d,]+)\/[\d,]+\s*<\/dd>/u', $res->body); |
|
| 94 | + $speTimeLimits=[ |
|
| 95 | 95 | "0103" => 2000, |
| 96 | 96 | "1102" => 2000, |
| 97 | 97 | "1402" => 2000, |
| 98 | 98 | "3602" => 2000, |
| 99 | 99 | "6B12" => 3000, |
| 100 | 100 | ]; |
| 101 | - $descPattern = "<h4>描述</h4>"; |
|
| 102 | - $inputPattern = "<h4>输入格式</h4>"; |
|
| 103 | - $outputPattern = "<h4>输出格式</h4>"; |
|
| 104 | - $sampleInputPattern = "<h4>样例输入</h4>"; |
|
| 105 | - $codePattren = "<pre>"; |
|
| 106 | - $codeClosePattern = "</pre>"; |
|
| 107 | - $sourcePattern = "<h4>来源</h4>"; |
|
| 108 | - if ($pid == "6703" || $pid == "1808") { |
|
| 109 | - if ($pid == "6703") { |
|
| 110 | - $timeLimit = 2000; |
|
| 111 | - $memoryLimit = 65536; |
|
| 101 | + $descPattern="<h4>描述</h4>"; |
|
| 102 | + $inputPattern="<h4>输入格式</h4>"; |
|
| 103 | + $outputPattern="<h4>输出格式</h4>"; |
|
| 104 | + $sampleInputPattern="<h4>样例输入</h4>"; |
|
| 105 | + $codePattren="<pre>"; |
|
| 106 | + $codeClosePattern="</pre>"; |
|
| 107 | + $sourcePattern="<h4>来源</h4>"; |
|
| 108 | + if ($pid=="6703" || $pid=="1808") { |
|
| 109 | + if ($pid=="6703") { |
|
| 110 | + $timeLimit=2000; |
|
| 111 | + $memoryLimit=65536; |
|
| 112 | 112 | } |
| 113 | - $descPattern = "<dt>描述</dt>"; |
|
| 114 | - $inputPattern = "<dt>输入</dt>"; |
|
| 115 | - $outputPattern = "<dt>输出</dt>"; |
|
| 116 | - $sampleInputPattern = "<dt>样例输入</dt>"; |
|
| 117 | - $sourcePattern = "<dt>来源</dt>"; |
|
| 113 | + $descPattern="<dt>描述</dt>"; |
|
| 114 | + $inputPattern="<dt>输入</dt>"; |
|
| 115 | + $outputPattern="<dt>输出</dt>"; |
|
| 116 | + $sampleInputPattern="<dt>样例输入</dt>"; |
|
| 117 | + $sourcePattern="<dt>来源</dt>"; |
|
| 118 | 118 | } else if (array_key_exists($pid, $speTimeLimits)) { |
| 119 | - $timeLimit = $speTimeLimits[$pid]; |
|
| 120 | - if ($pid == "3602") { |
|
| 121 | - $codePattren = '<code style="display: inline-block; padding: 2px; border: 1px solid black;">'; |
|
| 122 | - $codeClosePattern = "</code>"; |
|
| 119 | + $timeLimit=$speTimeLimits[$pid]; |
|
| 120 | + if ($pid=="3602") { |
|
| 121 | + $codePattren='<code style="display: inline-block; padding: 2px; border: 1px solid black;">'; |
|
| 122 | + $codeClosePattern="</code>"; |
|
| 123 | 123 | } |
| 124 | - } else if ($pid == "2902") { |
|
| 125 | - $outputPattern = "<p>输出格式</p>"; |
|
| 126 | - } else if ($pid == "5A01") { |
|
| 127 | - $inputPattern = "<p>输入格式</p>"; |
|
| 124 | + } else if ($pid=="2902") { |
|
| 125 | + $outputPattern="<p>输出格式</p>"; |
|
| 126 | + } else if ($pid=="5A01") { |
|
| 127 | + $inputPattern="<p>输入格式</p>"; |
|
| 128 | 128 | } |
| 129 | - $this->pro['pcode'] = 'CH'.$pid; |
|
| 130 | - $this->pro['solved_count'] = $passes; |
|
| 131 | - $this->pro['time_limit'] = $timeLimit; |
|
| 132 | - $this->pro['memory_limit'] = $memoryLimit; |
|
| 133 | - $this->pro['title'] = substr($pname, 5); |
|
| 134 | - $this->pro['OJ'] = $this->oid; |
|
| 135 | - $this->pro['input_type'] = 'standard input'; |
|
| 136 | - $this->pro['output_type'] = 'standard output'; |
|
| 137 | - $this->pro['contest_id'] = $rcname; |
|
| 138 | - $this->pro['index_id'] = $rpname; |
|
| 139 | - $this->pro['origin'] = "http://contest-hunter.org:83/contest/{$rcname}/{$rpname}"; |
|
| 140 | - $this->pro['source'] = $cname; |
|
| 129 | + $this->pro['pcode']='CH'.$pid; |
|
| 130 | + $this->pro['solved_count']=$passes; |
|
| 131 | + $this->pro['time_limit']=$timeLimit; |
|
| 132 | + $this->pro['memory_limit']=$memoryLimit; |
|
| 133 | + $this->pro['title']=substr($pname, 5); |
|
| 134 | + $this->pro['OJ']=$this->oid; |
|
| 135 | + $this->pro['input_type']='standard input'; |
|
| 136 | + $this->pro['output_type']='standard output'; |
|
| 137 | + $this->pro['contest_id']=$rcname; |
|
| 138 | + $this->pro['index_id']=$rpname; |
|
| 139 | + $this->pro['origin']="http://contest-hunter.org:83/contest/{$rcname}/{$rpname}"; |
|
| 140 | + $this->pro['source']=$cname; |
|
| 141 | 141 | |
| 142 | 142 | if (preg_match('/<a href="([0-9A-Za-z$\-_.+!*\'\(\),%:\/]*.pdf)">/', $res->body, $match)) { |
| 143 | - $res = Requests::get($match[1]); |
|
| 143 | + $res=Requests::get($match[1]); |
|
| 144 | 144 | file_put_contents(base_path("public/external/gym/$pname.pdf"), $res->body); |
| 145 | - $this->pro['description'] = "<a href=\"/external/gym/$rpname.pdf\">[Attachment Link]</a>"; |
|
| 146 | - $this->pro['input'] = ''; |
|
| 147 | - $this->pro['output'] = ''; |
|
| 148 | - $this->pro['sample'] = ''; |
|
| 149 | - $this->pro['note'] = ''; |
|
| 145 | + $this->pro['description']="<a href=\"/external/gym/$rpname.pdf\">[Attachment Link]</a>"; |
|
| 146 | + $this->pro['input']=''; |
|
| 147 | + $this->pro['output']=''; |
|
| 148 | + $this->pro['sample']=''; |
|
| 149 | + $this->pro['note']=''; |
|
| 150 | 150 | } else { |
| 151 | - $pos1 = strpos($res->body, $descPattern) + strlen($descPattern); |
|
| 152 | - $pos2 = strpos($res->body, $inputPattern, $pos1); |
|
| 153 | - $this->pro['description'] = trim(substr($res->body, $pos1, $pos2 - $pos1)); |
|
| 154 | - $pos1 = $pos2 + strlen($inputPattern); |
|
| 155 | - $pos2 = strpos($res->body, $outputPattern, $pos1); |
|
| 156 | - $this->pro['input'] = trim(substr($res->body, $pos1, $pos2 - $pos1)); |
|
| 157 | - $pos1 = $pos2 + strlen($outputPattern); |
|
| 158 | - $pos2 = strpos($res->body, $sampleInputPattern, $pos1); |
|
| 159 | - $this->pro['output'] = trim(substr($res->body, $pos1, $pos2 - $pos1)); |
|
| 160 | - $samples = []; |
|
| 161 | - while (($pos1 = strpos($res->body, $codePattren, $pos2)) !== FALSE) { |
|
| 162 | - $pos1 += strlen($codePattren); |
|
| 163 | - $pos2 = strpos($res->body, $codeClosePattern, $pos1); |
|
| 164 | - $sampleInput = ContestHunter::clearSampleText(trim(substr($res->body, $pos1, $pos2 - $pos1))); |
|
| 165 | - $pos1 = strpos($res->body, $codePattren, $pos2) + strlen($codePattren); |
|
| 166 | - $pos2 = strpos($res->body, $codeClosePattern, $pos1); |
|
| 167 | - $sampleOutput = ContestHunter::clearSampleText(trim(substr($res->body, $pos1, $pos2 - $pos1))); |
|
| 168 | - if (strpos($sampleInput, "输入") !== FALSE) { |
|
| 169 | - $lip = 7; |
|
| 170 | - $lop = 7; |
|
| 171 | - $si = 2; |
|
| 151 | + $pos1=strpos($res->body, $descPattern)+strlen($descPattern); |
|
| 152 | + $pos2=strpos($res->body, $inputPattern, $pos1); |
|
| 153 | + $this->pro['description']=trim(substr($res->body, $pos1, $pos2-$pos1)); |
|
| 154 | + $pos1=$pos2+strlen($inputPattern); |
|
| 155 | + $pos2=strpos($res->body, $outputPattern, $pos1); |
|
| 156 | + $this->pro['input']=trim(substr($res->body, $pos1, $pos2-$pos1)); |
|
| 157 | + $pos1=$pos2+strlen($outputPattern); |
|
| 158 | + $pos2=strpos($res->body, $sampleInputPattern, $pos1); |
|
| 159 | + $this->pro['output']=trim(substr($res->body, $pos1, $pos2-$pos1)); |
|
| 160 | + $samples=[]; |
|
| 161 | + while (($pos1=strpos($res->body, $codePattren, $pos2))!==FALSE) { |
|
| 162 | + $pos1+=strlen($codePattren); |
|
| 163 | + $pos2=strpos($res->body, $codeClosePattern, $pos1); |
|
| 164 | + $sampleInput=ContestHunter::clearSampleText(trim(substr($res->body, $pos1, $pos2-$pos1))); |
|
| 165 | + $pos1=strpos($res->body, $codePattren, $pos2)+strlen($codePattren); |
|
| 166 | + $pos2=strpos($res->body, $codeClosePattern, $pos1); |
|
| 167 | + $sampleOutput=ContestHunter::clearSampleText(trim(substr($res->body, $pos1, $pos2-$pos1))); |
|
| 168 | + if (strpos($sampleInput, "输入")!==FALSE) { |
|
| 169 | + $lip=7; |
|
| 170 | + $lop=7; |
|
| 171 | + $si=2; |
|
| 172 | 172 | do { |
| 173 | - $nip = strpos($sampleInput, "输入".$si, $lip); |
|
| 174 | - $nop = strpos($sampleOutput, "输出".$si, $lop); |
|
| 173 | + $nip=strpos($sampleInput, "输入".$si, $lip); |
|
| 174 | + $nop=strpos($sampleOutput, "输出".$si, $lop); |
|
| 175 | 175 | array_push($samples, [ |
| 176 | - "sample_input" => trim(substr($sampleInput, $lip, ($nip === FALSE ? strlen($sampleInput) : $nip) - $lip)), |
|
| 177 | - "sample_output" => trim(substr($sampleOutput, $lop, ($nop === FALSE ? strlen($sampleOutput) : $nop) - $lop)), |
|
| 176 | + "sample_input" => trim(substr($sampleInput, $lip, ($nip===FALSE ? strlen($sampleInput) : $nip)-$lip)), |
|
| 177 | + "sample_output" => trim(substr($sampleOutput, $lop, ($nop===FALSE ? strlen($sampleOutput) : $nop)-$lop)), |
|
| 178 | 178 | ]); |
| 179 | - $pl = 6 + strlen($si); |
|
| 180 | - $lip = $nip + $pl; |
|
| 181 | - $lop = $nop + $pl; |
|
| 182 | - } while ($nip !== FALSE); |
|
| 179 | + $pl=6+strlen($si); |
|
| 180 | + $lip=$nip+$pl; |
|
| 181 | + $lop=$nop+$pl; |
|
| 182 | + } while ($nip!==FALSE); |
|
| 183 | 183 | } else { |
| 184 | 184 | array_push($samples, [ |
| 185 | 185 | "sample_input" => $sampleInput, |
@@ -187,14 +187,14 @@ discard block |
||
| 187 | 187 | ]); |
| 188 | 188 | } |
| 189 | 189 | } |
| 190 | - $this->pro['sample'] = $samples; |
|
| 191 | - $pos1 = $pos2 + 6; |
|
| 192 | - $pos2 = strpos($res->body, $sourcePattern, $pos1); |
|
| 193 | - if ($pos2 === FALSE) $pos2 = strpos($res->body, "</article>", $pos1); |
|
| 194 | - $note = trim(substr($res->body, $pos1, $pos2 - $pos1)); |
|
| 195 | - while (substr($note, 0, 2) == '</') $note = trim(preg_replace('/<\/\w+>/', '', $note, 1)); |
|
| 196 | - if ($note == "<p> </p>") $note = ''; // cnmch |
|
| 197 | - $this->pro['note'] = $note; |
|
| 190 | + $this->pro['sample']=$samples; |
|
| 191 | + $pos1=$pos2+6; |
|
| 192 | + $pos2=strpos($res->body, $sourcePattern, $pos1); |
|
| 193 | + if ($pos2===FALSE) $pos2=strpos($res->body, "</article>", $pos1); |
|
| 194 | + $note=trim(substr($res->body, $pos1, $pos2-$pos1)); |
|
| 195 | + while (substr($note, 0, 2)=='</') $note=trim(preg_replace('/<\/\w+>/', '', $note, 1)); |
|
| 196 | + if ($note=="<p> </p>") $note=''; // cnmch |
|
| 197 | + $this->pro['note']=$note; |
|
| 198 | 198 | } |
| 199 | 199 | |
| 200 | 200 | $problem=$problemModel->pid($this->pro['pcode']); |
@@ -217,7 +217,7 @@ discard block |
||
| 217 | 217 | } |
| 218 | 218 | fwrite($f, "Finished loading problem list of {$cid} at {$now}".PHP_EOL); |
| 219 | 219 | } |
| 220 | - catch(Exception $e) { |
|
| 220 | + catch (Exception $e) { |
|
| 221 | 221 | fwrite($f, "Failed loading problem list of {$cid}".PHP_EOL); |
| 222 | 222 | } |
| 223 | 223 | } |
@@ -33,7 +33,9 @@ discard block |
||
| 33 | 33 | |
| 34 | 34 | private static function find($pattern, $subject) |
| 35 | 35 | { |
| 36 | - if (preg_match($pattern, $subject, $matches)) return $matches[1]; |
|
| 36 | + if (preg_match($pattern, $subject, $matches)) { |
|
| 37 | + return $matches[1]; |
|
| 38 | + } |
|
| 37 | 39 | return NULL; |
| 38 | 40 | } |
| 39 | 41 | |
@@ -50,12 +52,10 @@ discard block |
||
| 50 | 52 | $f = fopen(__DIR__."/contesthunter_status.log", "w") or die("Unable to open file!"); |
| 51 | 53 | try { |
| 52 | 54 | $res = Requests::get("http://contest-hunter.org:83/contest?type=1"); |
| 53 | - } |
|
| 54 | - catch (Exception $e) { |
|
| 55 | + } catch (Exception $e) { |
|
| 55 | 56 | try { // It seems that first query often fails |
| 56 | 57 | $res = Requests::get("http://contest-hunter.org:83/contest?type=1"); |
| 57 | - } |
|
| 58 | - catch (Exception $e2) { |
|
| 58 | + } catch (Exception $e2) { |
|
| 59 | 59 | fwrite($f, "Loaded contest list failed.".PHP_EOL); |
| 60 | 60 | fclose($f); |
| 61 | 61 | die("Loaded contest list failed."); |
@@ -70,7 +70,9 @@ discard block |
||
| 70 | 70 | $cname = urldecode($rcname); |
| 71 | 71 | $cid = substr($rcname, 0, 4); |
| 72 | 72 | $tag = NULL; |
| 73 | - if (preg_match('/「(.*?)」/u', $cname, $match)) $tag = $match[1]; |
|
| 73 | + if (preg_match('/「(.*?)」/u', $cname, $match)) { |
|
| 74 | + $tag = $match[1]; |
|
| 75 | + } |
|
| 74 | 76 | try { |
| 75 | 77 | $now=time()-$start; |
| 76 | 78 | fwrite($f, "Start loading problem list of {$cid} at {$now}".PHP_EOL); |
@@ -87,9 +89,13 @@ discard block |
||
| 87 | 89 | |
| 88 | 90 | $tests = ContestHunter::find('/<dt>测试点数<\/dt>\s*<dd>\s*(\d+)\s*<\/dd>/u', $res->body); |
| 89 | 91 | $totalTimeLimit = ContestHunter::find('/<dt>总时限<\/dt>\s*<dd>\s*([\d.]+) s\s*<\/dd>/u', $res->body); |
| 90 | - if ($tests) $timeLimit = $totalTimeLimit * 1000 / $tests; |
|
| 92 | + if ($tests) { |
|
| 93 | + $timeLimit = $totalTimeLimit * 1000 / $tests; |
|
| 94 | + } |
|
| 91 | 95 | $memoryLimit = ContestHunter::find('/<dt>总内存<\/dt>\s*<dd>\s*(\d+) MiB\s*<\/dd>/u', $res->body); |
| 92 | - if ($memoryLimit) $memoryLimit *= 1024; |
|
| 96 | + if ($memoryLimit) { |
|
| 97 | + $memoryLimit *= 1024; |
|
| 98 | + } |
|
| 93 | 99 | $passes = ContestHunter::find('/<dt>通过率<\/dt>\s*<dd>\s*([\d,]+)\/[\d,]+\s*<\/dd>/u', $res->body); |
| 94 | 100 | $speTimeLimits = [ |
| 95 | 101 | "0103" => 2000, |
@@ -190,10 +196,17 @@ discard block |
||
| 190 | 196 | $this->pro['sample'] = $samples; |
| 191 | 197 | $pos1 = $pos2 + 6; |
| 192 | 198 | $pos2 = strpos($res->body, $sourcePattern, $pos1); |
| 193 | - if ($pos2 === FALSE) $pos2 = strpos($res->body, "</article>", $pos1); |
|
| 199 | + if ($pos2 === FALSE) { |
|
| 200 | + $pos2 = strpos($res->body, "</article>", $pos1); |
|
| 201 | + } |
|
| 194 | 202 | $note = trim(substr($res->body, $pos1, $pos2 - $pos1)); |
| 195 | - while (substr($note, 0, 2) == '</') $note = trim(preg_replace('/<\/\w+>/', '', $note, 1)); |
|
| 196 | - if ($note == "<p> </p>") $note = ''; // cnmch |
|
| 203 | + while (substr($note, 0, 2) == '</') { |
|
| 204 | + $note = trim(preg_replace('/<\/\w+>/', '', $note, 1)); |
|
| 205 | + } |
|
| 206 | + if ($note == "<p> </p>") { |
|
| 207 | + $note = ''; |
|
| 208 | + } |
|
| 209 | + // cnmch |
|
| 197 | 210 | $this->pro['note'] = $note; |
| 198 | 211 | } |
| 199 | 212 | |
@@ -210,14 +223,12 @@ discard block |
||
| 210 | 223 | |
| 211 | 224 | $now=time()-$start; |
| 212 | 225 | fwrite($f, "Finished loading problem {$pid} at {$now}".PHP_EOL); |
| 213 | - } |
|
| 214 | - catch (Exception $e) { |
|
| 226 | + } catch (Exception $e) { |
|
| 215 | 227 | fwrite($f, "Failed loading problem {$pid}".PHP_EOL); |
| 216 | 228 | } |
| 217 | 229 | } |
| 218 | 230 | fwrite($f, "Finished loading problem list of {$cid} at {$now}".PHP_EOL); |
| 219 | - } |
|
| 220 | - catch(Exception $e) { |
|
| 231 | + } catch(Exception $e) { |
|
| 221 | 232 | fwrite($f, "Failed loading problem list of {$cid}".PHP_EOL); |
| 222 | 233 | } |
| 223 | 234 | } |
@@ -25,7 +25,7 @@ |
||
| 25 | 25 | * |
| 26 | 26 | * @var string |
| 27 | 27 | */ |
| 28 | - protected $redirectTo = '/home'; |
|
| 28 | + protected $redirectTo='/home'; |
|
| 29 | 29 | |
| 30 | 30 | /** |
| 31 | 31 | * Create a new controller instance. |
@@ -28,7 +28,7 @@ |
||
| 28 | 28 | * |
| 29 | 29 | * @var string |
| 30 | 30 | */ |
| 31 | - protected $redirectTo = '/'; |
|
| 31 | + protected $redirectTo='/'; |
|
| 32 | 32 | |
| 33 | 33 | /** |
| 34 | 34 | * Create a new controller instance. |
@@ -76,10 +76,10 @@ discard block |
||
| 76 | 76 | if (!$contestModel->judgeClearance($cid, Auth::user()->id)) { |
| 77 | 77 | return Redirect::route('contest_detail', ['cid' => $cid]); |
| 78 | 78 | } |
| 79 | - $contest_name = $contestModel->contestName($cid); |
|
| 80 | - $problemSet = $contestModel->contestProblems($cid, Auth::user()->id); |
|
| 81 | - $remainingTime = $contestModel->remainingTime($cid); |
|
| 82 | - $customInfo = $contestModel->getCustomInfo($cid); |
|
| 79 | + $contest_name=$contestModel->contestName($cid); |
|
| 80 | + $problemSet=$contestModel->contestProblems($cid, Auth::user()->id); |
|
| 81 | + $remainingTime=$contestModel->remainingTime($cid); |
|
| 82 | + $customInfo=$contestModel->getCustomInfo($cid); |
|
| 83 | 83 | if ($remainingTime<=0) { |
| 84 | 84 | $remainingTime=0; |
| 85 | 85 | } |
@@ -109,8 +109,8 @@ discard block |
||
| 109 | 109 | if (!$contestModel->judgeClearance($cid, Auth::user()->id)) { |
| 110 | 110 | return Redirect::route('contest_detail', ['cid' => $cid]); |
| 111 | 111 | } |
| 112 | - $contest_name = $contestModel->contestName($cid); |
|
| 113 | - $contest_ended = $contestModel->isContestEnded($cid); |
|
| 112 | + $contest_name=$contestModel->contestName($cid); |
|
| 113 | + $contest_ended=$contestModel->isContestEnded($cid); |
|
| 114 | 114 | $pid=$contestModel->getPid($cid, $ncode); |
| 115 | 115 | $pcode=$problemModel->pcode($pid); |
| 116 | 116 | |
@@ -186,10 +186,10 @@ discard block |
||
| 186 | 186 | if (!$contestModel->judgeClearance($cid, Auth::user()->id)) { |
| 187 | 187 | return Redirect::route('contest_detail', ['cid' => $cid]); |
| 188 | 188 | } |
| 189 | - $contest_name = $contestModel->contestName($cid); |
|
| 190 | - $problemSet = $contestModel->contestProblems($cid, Auth::user()->id); |
|
| 191 | - $customInfo = $contestModel->getCustomInfo($cid); |
|
| 192 | - $contestRank = $contestModel->contestRank($cid, Auth::user()->id); |
|
| 189 | + $contest_name=$contestModel->contestName($cid); |
|
| 190 | + $problemSet=$contestModel->contestProblems($cid, Auth::user()->id); |
|
| 191 | + $customInfo=$contestModel->getCustomInfo($cid); |
|
| 192 | + $contestRank=$contestModel->contestRank($cid, Auth::user()->id); |
|
| 193 | 193 | return view('contest.board.rank', [ |
| 194 | 194 | 'page_title'=>"Challenge", |
| 195 | 195 | 'navigation' => "Contest", |
@@ -213,9 +213,9 @@ discard block |
||
| 213 | 213 | if (!$contestModel->judgeClearance($cid, Auth::user()->id)) { |
| 214 | 214 | return Redirect::route('contest_detail', ['cid' => $cid]); |
| 215 | 215 | } |
| 216 | - $contest_name = $contestModel->contestName($cid); |
|
| 217 | - $customInfo = $contestModel->getCustomInfo($cid); |
|
| 218 | - $clarificationList = $contestModel->getClarificationList($cid); |
|
| 216 | + $contest_name=$contestModel->contestName($cid); |
|
| 217 | + $customInfo=$contestModel->getCustomInfo($cid); |
|
| 218 | + $clarificationList=$contestModel->getClarificationList($cid); |
|
| 219 | 219 | return view('contest.board.clarification', [ |
| 220 | 220 | 'page_title'=>"Clarification", |
| 221 | 221 | 'navigation' => "Contest", |
@@ -238,8 +238,8 @@ discard block |
||
| 238 | 238 | if (!$contestModel->judgeClearance($cid, Auth::user()->id)) { |
| 239 | 239 | return Redirect::route('contest_detail', ['cid' => $cid]); |
| 240 | 240 | } |
| 241 | - $contest_name = $contestModel->contestName($cid); |
|
| 242 | - $customInfo = $contestModel->getCustomInfo($cid); |
|
| 241 | + $contest_name=$contestModel->contestName($cid); |
|
| 242 | + $customInfo=$contestModel->getCustomInfo($cid); |
|
| 243 | 243 | return view('contest.board.print', [ |
| 244 | 244 | 'page_title'=>"Print", |
| 245 | 245 | 'navigation' => "Contest", |