Test Setup Failed
Push — master ( e2b9fb...698287 )
by
unknown
04:27
created

Core::__construct()   B

Complexity

Conditions 7
Paths 64

Size

Total Lines 33
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 7
eloc 20
nc 64
nop 3
dl 0
loc 33
rs 8.6666
c 0
b 0
f 0
1
<?php
2
namespace App\Http\Controllers\VirtualJudge;
3
4
use App\Models\SubmissionModel;
5
use App\Models\JudgerModel;
6
use App\Models\ProblemModel;
7
use App\Http\Controllers\VirtualJudge\Curl;
8
use App\Http\Controllers\VirtualJudge\NOJ\NOJ;
9
use App\Http\Controllers\VirtualJudge\CodeForces\CodeForces;
10
use App\Http\Controllers\VirtualJudge\ContestHunter\ContestHunter;
11
use App\Http\Controllers\VirtualJudge\POJ\POJ;
12
use App\Http\Controllers\VirtualJudge\Vijos\Vijos;
13
use App\Http\Controllers\VirtualJudge\PTA\PTA;
14
use Requests;
15
16
class Core extends Curl
17
{
18
    private $sub;
19
    public $post_data=[];
20
21
    public function __construct(& $sub, $oj, $all_data)
22
    {
23
        $this->sub=& $sub;
24
        $this->post_data=$all_data;
25
26
        if ($oj=='noj') {
27
            $NOJ=new NOJ($sub, $all_data);
28
            $NOJ->submit();
29
        }
30
31
        if ($oj=='codeforces') {
32
            $CodeForces=new CodeForces($sub, $all_data);
33
            $CodeForces->submit();
34
        }
35
36
        if ($oj=='contesthunter') {
37
            $ContestHunter=new ContestHunter($sub, $all_data);
38
            $ContestHunter->submit();
39
        }
40
41
        if ($oj=='poj') {
42
            $POJ=new POJ($sub, $all_data);
43
            $POJ->submit();
44
        }
45
46
        if ($oj=='vijos') {
47
            $Vijos=new Vijos($sub, $all_data);
48
            $Vijos->submit();
49
        }
50
51
        if ($oj=='pta') {
52
            $PTA=new PTA($sub, $all_data);
53
            $PTA->submit();
54
        }
55
    }
56
}
57
58
59
60
61
62
63
64
    // protected function uva_live_login($url1, $url2, $oj)
65
    // {
66
    //     $response=$this->grab_page($url1, $oj);
67
    //     if (!(strpos($response, 'Logout') !== false)&&(strpos($response, 'Login') !== false)) {
68
    //         $exploded = explode('<input type="hidden" name="cbsecuritym3" value="', $response);
69
    //         $cbsecuritym3 = explode('"', $exploded[1])[0];
70
71
    //         $exploded = explode('<input type="hidden" name="return" value="', $response);
72
    //         $return = explode('"', $exploded[1])[0];
73
74
    //         $exploded = explode('<input type="hidden" name="cbsecuritym3" value="', $response);
75
    //         $exploded = explode('<input type="hidden" name="', $exploded[1]);
76
    //         $any = explode('"', $exploded[1])[0];
77
78
79
    //         $params = [
80
    //             'username' => 'codemaster_uva',
81
    //             'passwd' => '123456',
82
    //             'op2' => 'login',
83
    //             'lang' => 'english',
84
    //             'force_session' => '1',
85
    //             'return' => $return,
86
    //             'message' => '0',
87
    //             'loginfrom' => 'loginmodule',
88
    //             'cbsecuritym3' =>  $cbsecuritym3,
89
    //             $any => '1',
90
    //             'remember' => 'yes',
91
    //             'Submit' => 'Login',
92
    //         ];
93
94
    //         $data=http_build_query($params);
95
    //         $this->login($url2, http_build_query($params), $oj);
96
    //     }
97
    // }
98
    // public function uva_live_submit($url, $oj)
99
    // {
100
    //     $this->sub['language']=substr($this->post_data["lang"], 1, 50);
101
    //     $this->sub['solution']=$this->post_data["solution"];
102
    //     $this->sub['pid']=$this->post_data["pid"];
103
104
    //     $code=$this->post_data["solution"];
105
    //     $lang=substr($this->post_data["lang"], 0, 1);
106
    //     $pro_id=$this->post_data['iid'];
107
108
    //     $params = [
109
    //         'problemid' => $pro_id,
110
    //         'category' => '',
111
    //         'language' => $lang,
112
    //         'code' => $code,
113
    //         'codeupl' => '',
114
    //     ];
115
    //     $data=http_build_query($params);
116
    //     $response=$this->post_data($url, $data, $oj, true);
117
    //     if (substr_count($response, 'Submission+received+with+ID')==0) {
118
    //         $exploded = explode('mosmsg=', $response);
119
    //         $this->sub['verdict'] = urldecode(explode('"', $exploded[2])[0]);
120
    //     }
121
    // }
122
    // private function uva()
123
    // {
124
    //     if (!isset($this->post_data["pid"])||!isset($this->post_data["iid"])||!isset($_COOKIE["user_handle"])&&!isset($this->post_data["solution"])) {
125
    //         redirect("/");
126
    //     }
127
    //     $response=$this->grab_page('https://uva.onlinejudge.org', 'uva');
128
    //     if (!(strpos($response, 'UVa Online Judge - Offline') !== false)&&strlen($response)!=0) {
129
    //         $this->uva_live_login('https://uva.onlinejudge.org', 'https://uva.onlinejudge.org/index.php?option=com_comprofiler&task=login', 'uva');
130
    //         $this->uva_live_submit('https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=save_submission', 'uva');
131
    //     } else {
132
    //         $this->sub['language']=substr($this->post_data["lang"], 1, 50);
133
    //         $this->sub['solution']=$this->post_data["solution"];
134
    //         $this->sub['pid']=$this->post_data["pid"];
135
    //         $this->sub['verdict']="Judge Error";
136
    //     }
137
    // }
138
    // private function uvalive()
139
    // {
140
    //     if (!isset($this->post_data["pid"])||!isset($this->post_data["iid"])||!isset($_COOKIE["user_handle"])&&!isset($this->post_data["solution"])) {
141
    //         redirect("/");
142
    //     }
143
    //     $this->uva_live_login('https://icpcarchive.ecs.baylor.edu', 'https://icpcarchive.ecs.baylor.edu/index.php?option=com_comprofiler&task=login', 'uvalive');
144
    //     $this->uva_live_submit('https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=save_submission', 'uvalive');
145
    // }
146
    // public function spoj_login()
147
    // {
148
    //     $response=$this->grab_page('http://www.spoj.com', 'spoj');
149
    //     if (!(strpos($response, 'sign-out') !== false)) {
150
    //         $params = [
151
    //             'next_raw' => "/",
152
    //             'autologin' => '1',
153
    //             'login_user' => 'codemaster_spoj',
154
    //             'password' => '123456'
155
    //         ];
156
157
    //         $data=http_build_query($params);
158
    //         $this->login('http://www.spoj.com/login', $data, 'spoj');
159
    //     }
160
    // }
161
    // public function multiexplode($delimiters, $string)
162
    // {
163
    //     $ready = str_replace($delimiters, $delimiters[0], $string);
164
    //     $launch = explode($delimiters[0], $ready);
165
    //     return  $launch;
166
    // }
167
    // public function spoj_submit()
168
    // {
169
    //     $x=0;
170
    //     for ($i=0;$i<strlen($this->post_data["lang"]);$i++) {
171
    //         if (is_numeric($this->post_data["lang"][$i])) {
172
    //             $x++;
173
    //         } else {
174
    //             break;
175
    //         }
176
    //     }
177
    //     $this->sub['language']=substr($this->post_data["lang"], $x, strlen($this->post_data["lang"]));
178
    //     $this->sub['solution']=$this->post_data["solution"];
179
    //     $this->sub['pid']=$this->post_data["pid"]; // 500A
180
    //     $lang=substr($this->post_data["lang"], 0, $x);
181
182
    //     $params = [
183
    //         'subm_file' => '',
184
    //         'file' => $this->post_data["solution"],
185
    //         'lang' => $lang,
186
    //         'problemcode' => $this->post_data['iid'],
187
    //         'submit' => 'Submit!',
188
    //     ];
189
190
    //     $data=http_build_query($params);
191
    //     $response=$this->post_data('http://www.spoj.com/submit/complete/', $data, 'spoj', true);
192
    //     if (substr_count($response, 'Solution submitted!')==0) {
193
    //         $exploded = explode('<p align="center">', $response);
194
    //         $this->sub['verdict'] = $this->multiexplode(["!","."], $exploded[1])[0];
195
    //     }
196
    // }
197
198
    // private function spoj()
199
    // {
200
    //     if (!isset($this->post_data["pid"])||!isset($this->post_data["iid"])||!isset($this->post_data["iid"])||!isset($_COOKIE["user_handle"])&&!isset($this->post_data["solution"])) {
201
    //         redirect("/");
202
    //     }
203
    //     $this->spoj_login();
204
    //     $this->spoj_submit();
205
    // }
206
207